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

解决腾讯定位 libs打包报错的问题

上级 56128bf5
<?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.hellouts">
<application>
<!--meta-data-->
<meta-data android:name="TencentMapSDK" android:value="您申请的腾讯定位App Key" />
</application>
</manifest>
......@@ -2,8 +2,8 @@
"name" : "HelloUTS",
"appid" : "__UNI__70BE9D0",
"description" : "",
"versionName" : "1.0.8",
"versionCode" : "108",
"versionName" : "1.0.9",
"versionCode" : "109",
"transformPx" : false,
/* 5+App特有相关 */
"app-plus" : {
......
......@@ -14,7 +14,7 @@
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="testAddToDecorView">添加TextView至视图顶层</button>
<button type="primary" @tap="testRemoveToDecorView">移除视图顶层的TextView</button>
<button type="primary" @tap="testResource">资源加载示例</button>
<button type="primary" @tap="gotoResourceDemo">资源加载示例</button>
<button type="primary" @tap="testLifecyle">activity生命周期监听</button>
</view>
......@@ -38,9 +38,11 @@
taskId:0
}
},
onUnload:function(){
},
methods: {
/**
* 测试延迟任务
*/
testTimer: function () {
doTimerTask({
start:function(response){
......@@ -57,6 +59,9 @@
},
});
},
/**
* 测试周期任务
*/
testInterval: function () {
var ret = doIntervalTask({
start:function(response){
......@@ -74,21 +79,31 @@
});
this.taskId = ret.taskId;
},
/**
* 取消周期任务
*/
testClearInterval: function () {
console.log(this.taskId);
clearIntervalTask(this.taskId);
},
/**
* 测试添加View实例至顶层容器
*/
testAddToDecorView: function () {
addViewToDecorView();
},
/**
* 测试移除顶层容器的View实例
*/
testRemoveToDecorView: function () {
removeViewToDecorView();
},
testResource: function () {
/**
* 跳转至资源加载演示界面
*/
gotoResourceDemo: function () {
uni.navigateTo({
url:'/pages/resource/resource'
})
......
......@@ -19,9 +19,12 @@
stringParam:"hello world",
}
},
onUnload:function(){
},
methods: {
/**
* 测试无参数调用
*/
testDoSthWithCallback: function () {
UTSHello.callWithoutParam(
......@@ -33,7 +36,11 @@
}
);
},
/**
* 测试字符串参数回调
*/
testDoSthWithString: function () {
UTSHello.callWithStringParam(
this.stringParam,
function(response){
......@@ -44,6 +51,9 @@
},
);
},
/**
* 测试json参数回调
*/
testDoSthWithJSON: function () {
var inputObject = {
inputText:this.stringParam
......
......@@ -20,12 +20,21 @@ import {
getAppContext
} from "io.dcloud.uts.android";
/**
* 定时任务参数封装
*/
type TimerOptions = {
start: (res: string) => void;
work: (res: string) => void;
/**
* 定时任务开始的回调
* @res 回调参数
*/
start: (res: string) => void;
/**
* 定时任务执行的回调
* @res 回调参数
*/
work: (res: string) => void;
};
......@@ -60,12 +69,14 @@ export function doIntervalTask(opts:TimerOptions) {
export function clearIntervalTask(taskId:number) {
clearInterval(taskId);
return { name: "clearIntervalTask"};
return { name: "clearIntervalTask"};
}
/**
* 实现一个添加view的 Runnable类
* 用法说明:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#%E5%8C%BF%E5%90%8D%E5%86%85%E9%83%A8%E7%B1%BB
*/
class AddUIRunnable extends Runnable {
override run():void {
......@@ -89,6 +100,10 @@ class AddUIRunnable extends Runnable {
}
};
/**
* 实现一个移除view的 Runnable类
* 用法说明:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#%E5%8C%BF%E5%90%8D%E5%86%85%E9%83%A8%E7%B1%BB
*/
class RemoveUIRunnable extends Runnable {
override run():void {
......@@ -102,27 +117,34 @@ class RemoveUIRunnable extends Runnable {
}
};
/**
* 实现添加view实例至decorview
*
*/
export function addViewToDecorView() {
let uiRunable = new AddUIRunnable();
getUniActivity()!.runOnUiThread(uiRunable)
}
/**
* 实现从decorview上移除指定view
*/
export function removeViewToDecorView() {
var uiRunable = new RemoveUIRunnable();
getUniActivity()!.runOnUiThread(uiRunable)
}
/**
* 引用资源路径
*/
export function getLogoPath(): string {
return logo;
}
/**
* 播放asset资源中的音频
*/
export function playAssetAudio() {
let assetManager = getAppContext()!.getAssets();
......@@ -135,26 +157,43 @@ export function playAssetAudio() {
}
/**
* 初始化应用生命周期监听
*
*/
export function initAppLifecycle(onLifecycleChange: (event:string) => void) {
/**
* activity 销毁生命周期回调
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivitydestroy
*/
onAppActivityDestroy(() => {
let eventName = "onAppActivityDestroy - " + Date.now();
onLifecycleChange(eventName);
console.log(eventName);
});
/**
* activity 失去焦点生命周期回调
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivitypause
*/
onAppActivityPause(() => {
let eventName = "onAppActivityPause - " + Date.now();
onLifecycleChange(eventName);
console.log(eventName);
});
/**
* activity 得到焦点的周期回调
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivityresume
*/
onAppActivityResume(() => {
let eventName = "onAppActivityResume - " + Date.now();
onLifecycleChange(eventName);
console.log(eventName);
});
/**
* activity 回退物理按键事件回调
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivityback
*/
onAppActivityBack(() => {
let eventName = "onAppActivityBack - " + Date.now();
onLifecycleChange(eventName);
......
export function log(msg: string) {
console.log(msg);
}
/**
* json参数格式定义
*/
type inputJSON = {
inputText: string,
errCode: number
}
/**
* json入参格式
*/
type JsonParamOptions = {
input: inputJSON;
success: (res: string) => void;
......@@ -13,7 +17,7 @@ type JsonParamOptions = {
/**
* 导出一个带callback的同步方法
* 导出无参的UTS函数
* @param opts
*/
export function callWithoutParam(success: () => void) {
......@@ -21,13 +25,17 @@ export function callWithoutParam(success: () => void) {
return { name: "doSthWithCallback" };
}
/**
* 导出一个字符串入参的UTS函数
*/
export function callWithStringParam(input: string, success: (res: string) => void) {
success(input);
return { name: "doSthWithCallback" };
}
/**
* 导出一个JSON入参的UTS函数
*/
export function callWithJSONParam(opts: JsonParamOptions) {
opts.input.errCode = 10;
opts.success(opts.input);
......
......@@ -26,9 +26,5 @@
<!-- A-GPS辅助定位权限,方便GPS快速准确定位 -->
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<application>
<!--meta-data-->
<meta-data android:name="TencentMapSDK" android:value="您申请的app key" />
</application>
</manifest>
{
"dependencies": [
{
"id": "com.tencent.map.geolocation:TencentLocationSdk-openplatform",
"source": "implementation 'com.tencent.map.geolocation:TencentLocationSdk-openplatform:7.4.9'"
}],
"minSdkVersion": 21
}
......@@ -16,6 +16,12 @@ import TencentLocationRequest from "com.tencent.map.geolocation.TencentLocationR
export function requestPremission() {
/**
* 同意隐私协议。重要!!
* 说明文档:https://lbs.qq.com/mobile/androidLocationSDK/androidGeoGuide/agreePrivacy
*/
TencentLocationManager.setUserAgreePrivacy(true);
// 注册一个请求回调
onAppActivityRequestPermissionsResult((requestCode: number,
permissions: MutableList<string>,
......@@ -28,8 +34,8 @@ export function requestPremission() {
console.log(permissions);
console.log(requestCode);
});
// 发起权限申请
// 发起权限申请
ActivityCompat.requestPermissions(
getUniActivity()!,
arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION,Manifest.permission.ACCESS_FINE_LOCATION), 1001);
......@@ -57,6 +63,10 @@ type LocationResponse = {
longitude?:number
}
/**
* 定位监听结果包装类
*/
class LocationOptionsWapper{
hostOption:LocationOptions;
......@@ -101,7 +111,7 @@ class SingleLocationListener extends TencentLocationListener {
reason:string ):void{
console.log(error);
console.log(reason);
console.log(location);
console.log(error);
this.hostOptionWraper.onLocationChanged(location,error,reason);
}
......@@ -118,6 +128,7 @@ class SingleLocationListener extends TencentLocationListener {
*/
export function getLocation(locationOptions: LocationOptions) {
let mLocationManager = TencentLocationManager.getInstance(getAppContext());
// 定位监听器封装
let locationOptionWrapper = new LocationOptionsWapper(locationOptions);
......@@ -130,7 +141,8 @@ export function getLocation(locationOptions: LocationOptions) {
}else{
locationRequest.setRequestLevel(TencentLocationRequest.REQUEST_LEVEL_GEO);
}
console.log(locationRequest);
mLocationManager.requestSingleFreshLocation(null, mLocationListener, Looper.getMainLooper());
mLocationManager.requestSingleFreshLocation(locationRequest, mLocationListener, Looper.getMainLooper());
return { name: "getLocation"};
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册