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

UTSAndroid 权限相关测试 进行中

上级 d090787c
<template> <template>
<view>
<button class="width:100%" @click="getAppContextClick" >getAppContext</button>
<button class="width:100%" @click="getUniActivityClick">getUniActivity</button>
<button class="width:100%" @click="getAppTempPathClick">getAppTempPath</button>
<button class="width:100%" @click="typeofClick">typeof</button>
<button class="width:100%" @click="checkSystemPermissionGrantedClick">checkSystemPermissionGranted</button>
<button class="width:100%" @click="getSystemPermissionDeniedClick">getSystemPermissionDenied</button>
<button class="width:100%" @click="gotoSystemPermissionActivityClick">gotoSystemPermissionActivity</button>
<button class="width:100%" @click="arrayPermissionFlowClick">组权限申请流程测试</button>
</view>
</template> </template>
<script> <script>
import {
getAppContextTest,
getUniActivityTest,
getAppTempPathTest,
typeofClickTest,
checkSystemPermissionGrantedTest,
getSystemPermissionDeniedTest,
gotoSystemPermissionActivityTest,
arrayPermissionFlowTest
} from '@/uni_modules/uts-platform-api'
/**
* 测试在页面生命周期之外,使用api
*/
export default {
data() {
return {}
},
methods: {
getAppContextClick() {
console.log("getAppContextClick")
if(getAppContextTest()){
uni.showToast({
title:'测试通过'
})
}else{
uni.showToast({
icon:'error',
title:'测试失败'
})
}
},
getUniActivityClick() {
getUniActivityTest()
},
getAppTempPathClick() {
getAppTempPathTest()
},
typeofClick() {
if(typeofClickTest()){
uni.showToast({
title:'测试通过'
})
}else{
uni.showToast({
icon:'error',
title:'测试失败'
})
}
},
checkSystemPermissionGrantedClick() {
if(checkSystemPermissionGrantedTest()){
uni.showToast({
title:'测试通过'
})
}else{
uni.showToast({
icon:'error',
title:'测试失败'
})
}
},
getSystemPermissionDeniedClick() {
if(getSystemPermissionDeniedTest()){
uni.showToast({
title:'测试通过'
})
}else{
uni.showToast({
icon:'error',
title:'测试失败'
})
}
},
gotoSystemPermissionActivityClick() {
gotoSystemPermissionActivityTest()
},
arrayPermissionFlowClick() {
arrayPermissionFlowTest()
}
}
}
</script> </script>
<style> <style>
......
{
"id": "uts-platform-api",
"displayName": "uts-platform-api",
"version": "1.0.0",
"description": "uts-platform-api",
"keywords": [
"uts-platform-api"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"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": "u",
"vue3": "u"
},
"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-platform-api
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[UTS 组件插件](https://uniapp.dcloud.net.cn/plugin/uts-component.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts)
\ No newline at end of file
import {
UTSAndroid
} from "io.dcloud.uts";
/**
* UTSAndroid.getAppContext
*/
export function getAppContextTest():boolean{
if(UTSAndroid.getAppContext() == null){
console.log("UTSAndroid.getAppContext() error")
return false
}
if(UTSAndroid.getUniActivity() == null){
console.log("UTSAndroid.getUniActivity() error")
return false
}
if(UTSAndroid.getUniActivity()!.getApplicationContext() == UTSAndroid.getAppContext()){
console.log(UTSAndroid.getUniActivity()!.getApplicationContext())
console.log(UTSAndroid.getAppContext())
return false
}
console.log("getAppContextTest success")
return true
}
export function getUniActivityTest(){
console.log(UTSAndroid.getUniActivity())
}
export function getAppTempPathTest(){
console.log(UTSAndroid.getAppTempPath())
}
export function typeofClickTest():boolean{
if(UTSAndroid.typeof('hello wrold') != 'string'){
return false
}
if(UTSAndroid.typeof(3.1415926) != 'number'){
return false
}
if(UTSAndroid.typeof(-100) != 'number'){
return false
}
if(UTSAndroid.typeof(false) != 'boolean'){
return false
}
if(UTSAndroid.typeof(true) != 'boolean'){
return false
}
if(UTSAndroid.typeof(new Date()) != 'object'){
return false
}
return true
}
export function checkSystemPermissionGrantedTest():boolean{
let ret = UTSAndroid.checkSystemPermissionGranted(UTSAndroid.getUniActivity()!,utsArrayOf('Manifest.permission.RECORD_AUDIO'))
console.log(ret)
let ret3 = UTSAndroid.checkSystemPermissionGranted(UTSAndroid.getUniActivity()!,utsArrayOf('Manifest.permission.ACCESS_WIFI_STATE','Manifest.permission.WRITE_CALENDAR','Manifest.permission.BLUETOOTH'))
console.log(ret3)
return true
}
export function getSystemPermissionDeniedTest():boolean{
let ret = UTSAndroid.getSystemPermissionDenied(UTSAndroid.getUniActivity()!,utsArrayOf('Manifest.permission.RECORD_AUDIO'))
console.log(ret)
let ret3 = UTSAndroid.getSystemPermissionDenied(UTSAndroid.getUniActivity()!,utsArrayOf('Manifest.permission.ACCESS_WIFI_STATE','Manifest.permission.WRITE_CALENDAR','Manifest.permission.BLUETOOTH'))
console.log(ret3)
return true
}
export function gotoSystemPermissionActivityTest(){
UTSAndroid.gotoSystemPermissionActivity(UTSAndroid.getUniActivity()!,utsArrayOf('Manifest.permission.RECORD_AUDIO'))
}
export function requestSystemPermission(){
// UTSAndroid.requestSystemPermission(UTSAndroid.getUniActivity()!,utsArrayOf('Manifest.permission.RECORD_AUDIO'))
// let permissionNeed : string[] = utsArrayOf("android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_FINE_LOCATION");
// UTSAndroid.requestSystemPermission(UTSAndroid.getUniActivity()!, permissionNeed, function (allRight:boolean,_grantedList:string[]) {
// if (allRight) {
// // 交给目前的location 引擎,真实执行
// console.log("all right:")
// }
// }, function (_doNotAskAgain:boolean,_grantedList:string[]) {
// console.log("用户拒绝了部分权限:")
// })
}
/**
* 一组权限,申请流程测试
*/
export function arrayPermissionFlowTest():boolean{
// if(!UTSAndroid.getSystemPermissionDenied(UTSAndroid.getUniActivity()!,utsArrayOf("android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"))){
// // 此时预期
// return false
// }
return true
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册