提交 b3beda80 编写于 作者: 杜庆泉's avatar 杜庆泉

uts location add

上级 820d5548
......@@ -2,8 +2,8 @@
"name" : "HelloUTS",
"appid" : "__UNI__70BE9D0",
"description" : "",
"versionName" : "1.0.1",
"versionCode" : "101",
"versionName" : "1.0.5",
"versionCode" : "105",
"transformPx" : false,
/* 5+App特有相关 */
"app-plus" : {
......
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="testGetlocation">获取定位信息</button>
</view>
</view>
</template>
<script>
import {requestPremission,getLocation} from "@/uni_modules/uts-tencentgeolocation";
export default {
data() {
return {
......@@ -13,7 +17,12 @@
}
},
methods: {
testGetlocation:function(e){
requestPremission();
var locationRet = getLocation();
console.log(locationRet);
},
}
}
</script>
......
import { getUniActivity,getAppContext } from "io.dcloud.uts.android";
import Rect from "android.graphics.Rect";
import Color from "android.graphics.Color";
import TextView from "android.widget.TextView";
......@@ -10,6 +9,17 @@ import Runnable from 'java.lang.Runnable';
import Exception from 'java.lang.Exception';
import MediaPlayer from 'android.media.MediaPlayer';
import logo from "../../static/logo.png";
import {
onAppActivityDestroy,
onAppActivityPause,
onAppActivityResume,
onAppActivityBack,
getUniActivity,
getAppContext
} from "io.dcloud.uts.android";
/**
* 定时任务参数封装
*/
......@@ -105,15 +115,7 @@ export function removeViewToDecorView() {
}
import logo from "../../static/logo.png";
import {
onAppActivityDestroy,
onAppActivityPause,
onAppActivityResume,
onAppActivityBack,
} from "io.dcloud.uts.android";
export function getLogoPath(): string {
......@@ -139,7 +141,6 @@ export function playAssetAudio() {
export function initAppLifecycle(onLifecycleChange: (event:string) => void) {
onAppActivityDestroy(() => {
let eventName = "onAppActivityDestroy - " + Date.now();
onLifecycleChange(eventName);
console.log(eventName);
......
{
"id": "uts-tencentgeolocation",
"displayName": "uts-tencentgeolocation",
"version": "1.0.0",
"description": "uts-tencentgeolocation",
"keywords": [
"uts-tencentgeolocation"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.0"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"Vue": {
"vue2": "n",
"vue3": "y"
},
"App": {
"app-android": "u",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
\ No newline at end of file
# uts-tencentgeolocation
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS 原生插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts/-/tree/dev)
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
package="io.dcloud.nativeresouce">
<!--permissions-->
<!-- 通过GPS得到精确位置 -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- 通过网络得到粗略位置 -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<!-- 访问网络,某些位置信息需要从网络服务器获取 -->
<uses-permission android:name="android.permission.INTERNET"/>
<!-- 访问WiFi状态,需要WiFi信息用于网络定位 -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<!-- 修改WiFi状态,发起WiFi扫描, 需要WiFi信息用于网络定位 -->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<!-- 访问网络状态, 检测网络的可用性,需要网络运营商相关信息用于网络定位 -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- 访问网络的变化, 需要某些信息用于网络定位 -->
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<!-- 蓝牙扫描权限 -->
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<!-- 前台service权限 -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<!-- 后台定位权限 -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
<!-- A-GPS辅助定位权限,方便GPS快速准确定位 -->
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<application>
<!--meta-data-->
<meta-data android:name="TencentMapSDK" android:value="JQXBZ-GYRLK-SZLJ2-APDLD-O5QUH-YQFLH" />
</application>
</manifest>
{
"libs": [],
"dependencies": [{
"id": "androidx.core:core",
"source": "implementation 'androidx.core:core:1.0.0'"
}, {
"id": "com.tencent.map.geolocation:TencentLocationSdk-openplatform",
"source": "implementation 'com.tencent.map.geolocation:TencentLocationSdk-openplatform:7.3.0'"
}],
"minSdkVersion": 21
}
import {
onAppActivityPause,
onAppActivityRequestPermissionsResult,
getUniActivity,
getAppContext
} from "io.dcloud.uts.android";
import ActivityCompat from "androidx.core.app.ActivityCompat";
import Manifest from "android.Manifest";
import Looper from "android.os.Looper";
import TencentLocationManager from "com.tencent.map.geolocation.TencentLocationManager";
import TencentLocationListener from "com.tencent.map.geolocation.TencentLocationListener";
import TencentLocation from "com.tencent.map.geolocation.TencentLocation";
export function requestPremission() {
// 注册一个请求回调
// onAppActivityRequestPermissionsResult((requestCode: number,
// permissions: Array<string>,
// grantResults: Array<number>) => {
// let eventName = "onAppActivityRequestPermissionsResult - " + Date.now();
// console.log(eventName);
// });
//发起权限申请
// let permissions:string[] = [Manifest.permission.ACCESS_COARSE_LOCATION]
ActivityCompat.requestPermissions(
getUniActivity()!,
arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION), 1001);
// 请求权限
return { name: "requestPremission"};
}
class SingleLocationListener extends TencentLocationListener {
override onLocationChanged(location:TencentLocation , error:Int ,
reason:string ):Unit{
console.log(location);
}
override onStatusUpdate(name:string, status:Int, desc:string ):Unit{
console.log(name);
}
}
export function getLocation() {
// 获取当前的地址回调
let mLocationManager = TencentLocationManager.getInstance(getAppContext());
let mLocationListener = new SingleLocationListener();
mLocationManager.requestSingleFreshLocation(null, mLocationListener, Looper.getMainLooper());
// 请求权限
return { name: "getLocation"};
}
\ No newline at end of file
-keepattributes *Annotation*
-keepclassmembers class ** {
public void on*Event(...);
}
-keep public class com.tencent.location.**{
public protected *;
}
-keepclasseswithmembernames class * {
native <methods>;
}
-keep class c.t.**{*;}
-keep class com.tencent.map.geolocation.**{*;}
-dontwarn org.eclipse.jdt.annotation.**
-dontwarn c.t.**
-dontwarn android.location.Location
-dontwarn android.net.wifi.WifiManager
-dontnote ct.**
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册