尝试访问相机时 Cordova 应用程序崩溃

Cordova application crashes when trying access the Camera

我有一个 Cordova 应用程序(运行 on Android),我已经实现了 Cordova Camera 插件,我有一个简单的 'click' 事件调用以下代码然后弹出留言:

"Allow MyHQAPP to access photos, media and files on your device?"

我点击'Allow'然后应用程序立即关闭??我检查了ADB错误日志,可以看到下面的错误

任何人都可以提出问题所在 - 请注意我正在使用 ngCordova 插件来实现相机功能 http://ngcordova.com/docs/plugins/camera/

08-07 11:33:19.712 14954 15032 E PluginManager: Uncaught exception from plugin
08-07 11:33:19.712 14954 15032 E PluginManager: android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com.mytechnologies.myapp_2017/cache/.Pic.jpg exposed beyond app through ClipData.Item.getUri()
08-07 11:33:19.712 14954 15032 E PluginManager:         at android.os.StrictMode.onFileUriExposed(StrictMode.java:1799)
08-07 11:33:19.712 14954 15032 E PluginManager:         at android.net.Uri.checkFileUriExposed(Uri.java:2346)
08-07 11:33:19.712 14954 15032 E PluginManager:         at android.content.ClipData.prepareToLeaveProcess(ClipData.java:845)
08-07 11:33:19.712 14954 15032 E PluginManager:         at android.content.Intent.prepareToLeaveProcess(Intent.java:8941)
08-07 11:33:19.712 14954 15032 E PluginManager:         at android.content.Intent.prepareToLeaveProcess(Intent.java:8926)
08-07 11:33:19.712 14954 15032 E PluginManager:         at android.app.Instrumentation.execStartActivity(Instrumentation.java:1690)
08-07 11:33:19.712 14954 15032 E PluginManager:         at android.app.Activity.startActivityForResult(Activity.java:4291)
08-07 11:33:19.712 14954 15032 E PluginManager:         at org.apache.cordova.CordovaActivity.startActivityForResult(CordovaActivity.java:342)
08-07 11:33:19.712 14954 15032 E PluginManager:         at android.app.Activity.startActivityForResult(Activity.java:4249)
08-07 11:33:19.712 14954 15032 E PluginManager:         at org.apache.cordova.CordovaInterfaceImpl.startActivityForResult(CordovaInterfaceImpl.java:66)
08-07 11:33:19.712 14954 15032 E PluginManager:         at org.apache.cordova.camera.CameraLauncher.takePicture(CameraLauncher.java:259)
08-07 11:33:19.712 14954 15032 E PluginManager:         at org.apache.cordova.camera.CameraLauncher.callTakePicture(CameraLauncher.java:233)
08-07 11:33:19.712 14954 15032 E PluginManager:         at org.apache.cordova.camera.CameraLauncher.execute(CameraLauncher.java:168)
08-07 11:33:19.712 14954 15032 E PluginManager:         at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98) 
08-07 11:33:19.712 14954 15032 E PluginManager:         at org.apache.cordova.PluginManager.exec(PluginManager.java:132)
08-07 11:33:19.712 14954 15032 E PluginManager:         at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:57)
08-07 11:33:19.712 14954 15032 E PluginManager:         at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41)
08-07 11:33:19.712 14954 15032 E PluginManager:         at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
08-07 11:33:19.712 14954 15032 E PluginManager:         at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:7)
08-07 11:33:19.712 14954 15032 E PluginManager:         at android.os.Handler.dispatchMessage(Handler.java:102)
08-07 11:33:19.712 14954 15032 E PluginManager:         at android.os.Looper.loop(Looper.java:154)
08-07 11:33:19.712 14954 15032 E PluginManager:         at android.os.HandlerThread.run(HandlerThread.java:61)
08-07 11:33:21.836 13427 13427 E SimcardDataModel: provide unsupported slot id 0

在我的 js 控制器中

$scope.uploadFromCamera = function () {
    console.log('Upload from Camera');

    var options = {
        quality: 75,
        destinationType: Camera.DestinationType.DATA_URL,
        sourceType: Camera.PictureSourceType.CAMERA,
        allowEdit: true,
        encodingType: Camera.EncodingType.JPEG,
        targetWidth: 300,
        targetHeight: 300,
        popoverOptions: CameraPopoverOptions,
        saveToPhotoAlbum: false
    };

    $cordovaCamera.getPicture(options).then(function (imageData) {
        $scope.imgURI = "data:image/jpeg;base64," + imageData;
        console.log($scope.imgURI);
        console.log($scope);
    }, function (err) {
        // An error occured. Show a message to the user
    });
}

//科尔多瓦信息 节点版本:v6.10.3 科尔多瓦版本:6.0.0

Config.xml 文件:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.mytechnologies.fakename_2017" versionCode='20002' version="2.0.2" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>MyAPP</name>
  <description>
    A sample Apache Cordova application that responds to the deviceready event.
  </description>
  <author email="dev@cordova.apache.org" href="http://cordova.io">
    Apache Cordova Team
  </author>
  <content src="index.html" />
  <plugin name="cordova-plugin-whitelist" spec="1" />
  <access origin="*" />
  <allow-intent href="http://*/*" />
  <allow-intent href="https://*/*" />
  <allow-intent href="tel:*" />
  <allow-intent href="sms:*" />
  <allow-intent href="mailto:*" />
  <allow-intent href="geo:*" />
  <platform name="android">
    <allow-intent href="market:*" />
  </platform>
  <platform name="ios">
    <allow-intent href="itms:*" />
    <allow-intent href="itms-apps:*" />
  </platform>
  <engine name="android" spec="~5.2.2" />
  <icon src="res/icon.png" />
</widget>

插件:

cordova-plugin-camera,cordova-plugin-compat,cordova-plugin-whitelist

cordova-plugin-camera 2.1.1 "Camera" cordova-plugin-whitelist 1.3.0 "Whitelist"

尝试将 cordova-plugin-camera 的版本更改为 2.4.1