# UTSAndroid app-android平台专有内置对象。在uni-app和uni-app x的uts环境中均可使用。 ## 静态方法 ### onAppConfigChange(callback) ### offAppConfigChange(callback?) ### onAppTrimMemory(callback?) ### offAppTrimMemory(callback?) ### onAppActivityPause(callback) ### offAppActivityPause(callback?) ### onAppActivityResume(callback) ### offAppActivityResume(callback?) ### onAppActivityDestroy(callback) ### offAppActivityDestroy(callback?) ### onAppActivityResult(callback) ### offAppActivityResult(callback?) ### onAppActivityBack(callback) ### offAppActivityBack(callback?) ### getAppContext() ### getUniActivity() ### getResourcePath(resourceName) ### exit() ### getDispatcher(threadName) ```uts // 不传任何参数,得到是当前代码运行线程 let currentDispatcher = UTSAndroid.getDispatcher() console.log("currentDispatcher",currentDispatcher) // 期望在 io 任务队列执行 UTSAndroid.getDispatcher("io").async(function(_){ console.log("当前任务执行在",Thread.currentThread().getName()) // 期望在 主线程 任务队列执行 UTSAndroid.getDispatcher("main").async(function(_){ console.log("当前任务执行在",Thread.currentThread().getName()) currentDispatcher.async(function(_){ console.log("起始任务执行在",Thread.currentThread().getName()) },null) },null) },null) ``` ### getAppId() ### getOsTheme() ### isUniMp() ### getAppName() ### getAppVersion() ### getInnerVersion() ### isUniAppX() ### getAppCachePath * 如果编译报错找不到该方法,手动删除“uniapp-runextension”插件重新安装 或者 重新下载安装最新版本 HBuilder X 即可修复* ### rpx2px(rpx:number) : number; ### devicePX2px(devicePX:number) : number; ### isPrivacyAgree() : boolean; ### setPrivacyAgree(state:boolean):void; ### resetPrivacyAgree():void; ### requestSystemPermission ```uts let permissionNeed = ["android.permission.CAMERA"] // 请求权限,并跳转拍照界面 UTSAndroid.requestSystemPermission(UTSAndroid.getUniActivity()!, permissionNeed, function (allRight : boolean, _ : string[]) { if (allRight) { UTSAndroid.onAppActivityResult((requestCode : Int, resultCode : Int, data ?: Intent) => { if ((requestCode == 1001) && (resultCode == Activity.RESULT_OK)) { if (data != null) { let bundle = data.getExtras(); let mImageBitmap = bundle!.get("data") as Bitmap; let bitmapPath = UTSAndroid.getUniActivity()!.getExternalCacheDir()!.getPath() + "/photo.png" console.log(bitmapPath); try { mImageBitmap.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream(bitmapPath)) } catch (e) { } imageDone(bitmapPath); } } }); let takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //resolveActivity 返回可处理 Intent 的第一个 Activity 组件 if (takePictureIntent.resolveActivity(UTSAndroid.getUniActivity()!.getPackageManager()) != null) { UTSAndroid.getUniActivity()!.startActivityForResult(takePictureIntent, 1001); } } else { //callback(false,"用户拒绝了部分权限") } }, function (_ : boolean, _ : string[]) { //callback(false,"用户拒绝了部分权限") }) ``` ### checkSystemPermissionGranted ### gotoSystemPermissionActivity ### getSystemPermissionDenied ### convert2AbsFullPath ### getFileProviderUri ```ts // 使用外部应用打开项目内置图片资源 let file = new File(UTSAndroid.getResourcePath("static/logo.png")) const uri = UTSAndroid.getFileProviderUri(file) const intent = new Intent(Intent.ACTION_VIEW, uri) intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) const context = UTSAndroid.getUniActivity()!; context.startActivity(intent); ```