313 lines
8.5 KiB
Plaintext
313 lines
8.5 KiB
Plaintext
<template>
|
|
<!-- #ifdef APP-ANDROID -->
|
|
<scroll-view style="flex: 1">
|
|
<view>
|
|
<view class="uni-padding-wrap uni-common-mt">
|
|
<view class="uni-hello-text"> 逐一点击执行,观察测试反馈 </view>
|
|
</view>
|
|
|
|
<button @click="getAppContextClick">getAppContext</button>
|
|
<button @click="getUniActivityClick">getUniActivity</button>
|
|
<button @click="getJavaClassClick">getJavaClass</button>
|
|
<button @click="getAppTempPathClick">getAppTempPath</button>
|
|
<button @click="typeofClick">typeof</button>
|
|
<button @click="arrayPermissionFlowClick">组权限申请流程测试</button>
|
|
<button @click="singlePermissionFlowClick">单权限申请流程测试</button>
|
|
<button @click="dispatchAsyncClick">任务分发测试</button>
|
|
<button @click="pathTestClick">路径转换测试</button>
|
|
<button @click="privacyStateClick">隐私协议状态测试</button>
|
|
<button @click="privacyStateCallBackClick">隐私协议回调测试</button>
|
|
<view class="uni-padding-wrap uni-common-mt">
|
|
<view class="uni-hello-text">
|
|
1. 当前页面已通过initAppLifecycle函数注册了生命周期监听。
|
|
</view>
|
|
<view class="uni-hello-text">
|
|
2. 手动切换其他APP再返回,可在控制台和界面观察事件日志
|
|
</view>
|
|
</view>
|
|
<view class="uni-padding-wrap uni-common-mt">
|
|
<view class="text-box" scroll-y="true">
|
|
<text>{{ text }}</text>
|
|
</view>
|
|
</view>
|
|
<button @click="gotoSystemPermissionActivityClick">
|
|
手动申请权限测试
|
|
</button>
|
|
<button @tap="testGoOtherActivity">跳转拍照界面</button>
|
|
<button @tap="testUnRegLifecycle">取消注册周期函数</button>
|
|
<image :src="selectImage" v-if="selectImage"></image>
|
|
<view class="uni-padding-wrap uni-common-mt">
|
|
<view class="uni-hello-text"> 获取设备信息,观察是否符合预期 </view>
|
|
</view>
|
|
<button @tap="getDeviceInfoClick">获取设备基础信息</button>
|
|
<button @tap="getFileProviderUriClick">使用外部应用访问私有文件</button>
|
|
</view>
|
|
</scroll-view>
|
|
<!-- #endif -->
|
|
</template>
|
|
|
|
<script>
|
|
// #ifdef APP-ANDROID
|
|
import {
|
|
getAppContextTest,
|
|
getUniActivityTest,
|
|
getJavaClassTest,
|
|
getAppTempPathTest,
|
|
typeofClickTest,
|
|
gotoSystemPermissionActivityTest,
|
|
arrayPermissionFlowTest,
|
|
singlePermissionFlowTest,
|
|
dispatchAsyncTest,
|
|
convert2AbsFullPathTest,
|
|
unRegLifecycle,
|
|
initAppLifecycle,
|
|
gotoCameraTake,
|
|
getDeviceInfoTest,
|
|
privacyStateTest
|
|
} from '@/uni_modules/uts-platform-api'
|
|
// #endif
|
|
|
|
// #ifdef APP-ANDROID
|
|
import {
|
|
UTSAcvitiyLifeCycleCallback,
|
|
UTSAcvitiyKeyEventCallback,
|
|
UTSActivityWindowCallback,
|
|
UTSActivityCallback,
|
|
UTSActivityComponentCallback,
|
|
onCallbackChange
|
|
} from '@/uni_modules/uts-syntaxcase'
|
|
|
|
|
|
import File from 'java.io.File';
|
|
import Intent from 'android.content.Intent';
|
|
// #endif
|
|
|
|
/**
|
|
* 测试在页面生命周期之外,使用api
|
|
*/
|
|
export default {
|
|
data() {
|
|
return {
|
|
text: '',
|
|
selectImage: '',
|
|
}
|
|
},
|
|
unmounted() {
|
|
},
|
|
onLoad: function () {
|
|
// #ifdef APP-ANDROID
|
|
let that = this
|
|
initAppLifecycle(function (eventLog) {
|
|
// 展示捕捉到的声明周期日志
|
|
let nextLine = that.text + eventLog
|
|
that.text = nextLine
|
|
let nextLineFlag = that.text + '\n'
|
|
that.text = nextLineFlag
|
|
})
|
|
// #endif
|
|
},
|
|
methods: {
|
|
// #ifdef APP-ANDROID
|
|
privacyStateClick() {
|
|
privacyStateTest(function (ret, desc) {
|
|
if (ret) {
|
|
uni.showToast({
|
|
title: '测试通过',
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
icon: 'none',
|
|
title: '失败:' + desc,
|
|
})
|
|
}
|
|
})
|
|
},
|
|
privacyStateCallBackClick() {
|
|
|
|
let isAgree : boolean = true
|
|
|
|
const cb = (ret : PrivacyOption) => {
|
|
console.log('privacyStateCallBackTest->' + ret.isAgree)
|
|
if (ret.isAgree == isAgree) {
|
|
uni.showToast({
|
|
title: '测试通过'
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
icon: 'none',
|
|
title: '失败'
|
|
})
|
|
}
|
|
}
|
|
// 先重置用户同意状态
|
|
UTSAndroid.onPrivacyAgreeChange(cb)
|
|
UTSAndroid.setPrivacyAgree(isAgree)
|
|
UTSAndroid.offPrivacyAgreeChange(cb)
|
|
setTimeout(function () {
|
|
console.log('privacyStateCallBackTest->false')
|
|
|
|
UTSAndroid.setPrivacyAgree(false)
|
|
}, 5000);
|
|
},
|
|
getDeviceInfoClick() {
|
|
this.text = getDeviceInfoTest()
|
|
},
|
|
testGoOtherActivity() {
|
|
var that = this
|
|
let ret = gotoCameraTake(function (file) {
|
|
// 展示捕捉到的声明周期日志
|
|
console.log(file)
|
|
that.selectImage = 'file://' + file
|
|
})
|
|
|
|
if (!ret) {
|
|
uni.showToast({
|
|
icon: 'none',
|
|
title: '测试失败',
|
|
})
|
|
}
|
|
},
|
|
testUnRegLifecycle() {
|
|
// 取消注册生命周期
|
|
unRegLifecycle()
|
|
},
|
|
getJavaClassClick() {
|
|
if (getJavaClassTest()) {
|
|
uni.showToast({
|
|
title: '测试通过'
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
icon: 'error',
|
|
title: '测试失败'
|
|
})
|
|
}
|
|
},
|
|
getAppContextClick() {
|
|
if (getAppContextTest()) {
|
|
uni.showToast({
|
|
title: '测试通过',
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
icon: 'error',
|
|
title: '测试失败',
|
|
})
|
|
}
|
|
},
|
|
|
|
getUniActivityClick() {
|
|
if (getUniActivityTest()) {
|
|
uni.showToast({
|
|
title: '测试通过',
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
icon: 'error',
|
|
title: '测试失败',
|
|
})
|
|
}
|
|
},
|
|
pathTestClick() {
|
|
if (convert2AbsFullPathTest()) {
|
|
uni.showToast({
|
|
title: '测试通过',
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
icon: 'error',
|
|
title: '测试失败',
|
|
})
|
|
}
|
|
},
|
|
getFileProviderUriClick() {
|
|
let file = new File(UTSAndroid.getResourcePath("static/logo.png"))
|
|
const uri = UTSAndroid.getFileProviderUri(file)
|
|
console.log("uri", uri.toString())
|
|
const intent = new Intent(Intent.ACTION_VIEW, uri)
|
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) // 添加权限标志
|
|
const context = UTSAndroid.getUniActivity()!;
|
|
context.startActivity(intent);
|
|
},
|
|
getAppTempPathClick() {
|
|
if (getAppTempPathTest()) {
|
|
uni.showToast({
|
|
title: '测试通过',
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
icon: 'error',
|
|
title: '测试失败',
|
|
})
|
|
}
|
|
},
|
|
dispatchAsyncClick() {
|
|
dispatchAsyncTest(function (ret, desc) {
|
|
if (ret) {
|
|
uni.showToast({
|
|
title: '测试通过',
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
icon: 'none',
|
|
title: '失败:' + desc,
|
|
})
|
|
}
|
|
})
|
|
},
|
|
typeofClick() {
|
|
if (typeofClickTest()) {
|
|
uni.showToast({
|
|
title: '测试通过',
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
icon: 'error',
|
|
title: '测试失败',
|
|
})
|
|
}
|
|
},
|
|
|
|
gotoSystemPermissionActivityClick() {
|
|
gotoSystemPermissionActivityTest()
|
|
},
|
|
arrayPermissionFlowClick() {
|
|
arrayPermissionFlowTest(function (ret, desc) {
|
|
if (ret) {
|
|
uni.showToast({
|
|
icon: 'none',
|
|
title: '测试通过',
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
icon: 'none',
|
|
title: '失败:' + desc,
|
|
})
|
|
}
|
|
})
|
|
},
|
|
singlePermissionFlowClick() {
|
|
singlePermissionFlowTest(function (ret, desc) {
|
|
if (ret) {
|
|
uni.showToast({
|
|
icon: 'none',
|
|
title: '测试通过',
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
icon: 'none',
|
|
title: '失败:' + desc,
|
|
})
|
|
}
|
|
})
|
|
},
|
|
// #endif
|
|
},
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
.testButton {
|
|
width: 100%;
|
|
}
|
|
</style> |