gpt4 book ai didi

android - Cordova Android 应用程序在拍摄照片时因 RecoverableSecurityException 而崩溃

转载 作者:行者123 更新时间:2023-12-05 00:01:50 25 4
gpt4 key购买 nike

Cordova android 应用程序在使用相机拍摄照片时经常崩溃。 crashlytics 的堆栈跟踪是

Caused by android.app.RecoverableSecurityException: com.myapp.appname has no access to content://media/external/images/media/131613
at android.app.RecoverableSecurityException$1.createFromParcel(RecoverableSecurityException.java:197)
at android.app.RecoverableSecurityException$1.createFromParcel(RecoverableSecurityException.java:194)
at android.os.Parcel.readParcelable(Parcel.java:3295)
at android.os.Parcel.createExceptionOrNull(Parcel.java:2382)
at android.os.Parcel.createException(Parcel.java:2371)
at android.os.Parcel.readException(Parcel.java:2354)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
at android.content.ContentProviderProxy.delete(ContentProviderNative.java:624)
at android.content.ContentResolver.delete(ContentResolver.java:2386)
at android.content.ContentResolver.delete(ContentResolver.java:2344)
at org.apache.cordova.camera.CameraLauncher.checkForDuplicateImage(CameraLauncher.java:1234)
at org.apache.cordova.camera.CameraLauncher.cleanup(CameraLauncher.java:1200)
at org.apache.cordova.camera.CameraLauncher.processResultFromCamera(CameraLauncher.java:597)
at org.apache.cordova.camera.CameraLauncher.onActivityResult(CameraLauncher.java:829)
at org.apache.cordova.CordovaInterfaceImpl.onActivityResult(CordovaInterfaceImpl.java:160)
at org.apache.cordova.CordovaActivity.onActivityResult(CordovaActivity.java:368)
at android.app.Activity.dispatchActivityResult(Activity.java:8627)
at android.app.ActivityThread.deliverResults(ActivityThread.java:5466)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5514)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2380)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:257)
at android.app.ActivityThread.main(ActivityThread.java:8335)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:626)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1032)
大多数崩溃发生在搭载 Android 11 和 12 的三星设备上。
拍摄照片的代码是
    navigator.camera.getPicture(onPhotoDataSuccess, onPhotoCaptureFail, {
quality: 100,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: 1,
encodingType: 0,
allowEdit: false,
targetWidth: 1024,
targetHeight: 768,
correctOrientation: true
});
我已尝试通过在相机插件的 CameraLauncher.java 文件中添加 try catch 来解决此问题,如建议 here但在那之后相机没有打开
private void checkForDuplicateImage(int type) {
int diff = 1;
Uri contentStore = whichContentStore();
Cursor cursor = queryImgDB(contentStore);
int currentNumOfImages = cursor.getCount();

if (type == FILE_URI && this.saveToPhotoAlbum) {
diff = 2;
}

// delete the duplicate file if the difference is 2 for file URI or 1 for Data URL
if ((currentNumOfImages - numPics) == diff) {
cursor.moveToLast();
int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID)));
if (diff == 2) {
id--;
}
Uri uri = Uri.parse(contentStore + "/" + id);
ContentResolver contentResolver = this.cordova.getActivity().getContentResolver();

try {
contentResolver.delete(uri, null, null);
} catch (SecurityException e) {
if (this.manualMediaStoreCleanup && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {

ArrayList<Uri> collection = new ArrayList<>();
collection.add(uri);
PendingIntent pendingIntent = MediaStore.createDeleteRequest(contentResolver, collection);
try {
this.cordova.getActivity().startIntentSenderForResult(pendingIntent.getIntentSender(),
42, null, 0, 0,
0, null);

} catch (IntentSender.SendIntentException ex) {
LOG.e(LOG_TAG, "Error starting deleteRequest intent");
}

} else if (this.manualMediaStoreCleanup && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {

//if exception is recoverable then again send delete request using intent
if (e instanceof RecoverableSecurityException) {
RecoverableSecurityException exception = (RecoverableSecurityException) e;
PendingIntent pendingIntent = exception.getUserAction().getActionIntent();

try {
mediaStoreUri = uri;
this.cordova.setActivityResultCallback(this);
this.cordova.getActivity().startIntentSenderForResult(pendingIntent.getIntentSender(),
RECOVERABLE_DELETE_REQUEST, null, 0, 0,
0, null);
} catch (IntentSender.SendIntentException ex) {
LOG.e(LOG_TAG, "Error starting RecoverableSecurityException intent");
}
}
} else {
LOG.e(LOG_TAG, "Error during media store file deletion");
}

}

cursor.close();
}
}
有人遇到过这个问题吗?任何帮助将非常感激
使用的版本是:-
  • Cordova :10.0.0 (cordova-lib@10.1.0)
  • Cordova 机器人:10.1.1
  • Cordova 插件相机:6.0.0
  • 设备:搭载 Android 11 或 12 的三星设备
  • 最佳答案

    我在 Android 10 设备 (Armor_X8) 上遇到了同样的问题。
    一切都是最新的。

    "plugin_metadata": {
    "cordova-plugin-app-version": "0.1.12",
    "cordova-plugin-device": "2.0.3",
    "cordova-plugin-geolocation": "4.1.0",
    "es6-promise-plugin": "4.2.2",
    "cordova-plugin-screen-orientation": "3.0.2",
    "cordova-plugin-inappbrowser": "5.0.0",
    "@red-mobile/cordova-plugin-barcodescanner": "9.0.7",
    "cordova-plugin-network-information": "3.0.0",
    "cordova-plugin-camera": "6.0.0"
    }

    关于android - Cordova Android 应用程序在拍摄照片时因 RecoverableSecurityException 而崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72393586/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com