HBuilder X 3.6.9 版本已支持此函数。
Hello UTS 生命周期示例中增加了跳转系统拍照,返回获取图片的示例。其中有onActivitResult 使用示例。关键代码如下:
export function goOtherActivity(imageDone: (event:string) => void):boolean {
// 检查相关权限是否已经具备
if (ActivityCompat.checkSelfPermission(getUniActivity()!, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
// 不具备权限,申请权限,并且告知用户监听失败
ActivityCompat.requestPermissions(getUniActivity()!, arrayOf(Manifest.permission.CAMERA), 1002)
return false;
}
onAppActivityResult((requestCode: Int, resultCode: Int, data?: Intent) => {
let eventName = "onAppActivityResult - requestCode:" + requestCode + " -resultCode:"+resultCode + " -data:"+JSON.stringify(data);
console.log(eventName);
if ((requestCode == 1001) && (resultCode == Activity.RESULT_OK)) {
if (data != null) {
let bundle = data.getExtras();
let mImageBitmap = bundle!.get("data") as Bitmap;
let bitmapPath = 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(getUniActivity()!.getPackageManager()) != null) {
getUniActivity()!.startActivityForResult(takePictureIntent, 1001);
}
return true;
}
具体参考这里
https://gitcode.net/dcloud/hello-uts/-/blob/master/pages/lifecycle/lifecycle.vue
唐锦佳钰
怎么没有文件上传
2024-02-25 23:37