index.uts 3.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
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
}