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