0

在某些版本的 Android 应用程序中,当从相机胶卷中选择图像时会崩溃。它在 android 5 中运行良好,但有时应用程序在 4.2、4.3 中崩溃。

 <a href="#" data-rel="popup" data-position-to="window" data-role="button" data-inline="true" onclick="getPhoto(pictureSource.PHOTOLIBRARY);"  data-theme="a"   data-transition="pop" class=" change_but" >Change Photo</a>


function getPhoto(source) {
    navigator.camera.getPicture(onPhotoURISuccess, onFail, {
    quality: 30,
    targetWidth: 600,
    targetHeight: 600,
    destinationType: destinationType.FILE_URI,
    sourceType: source
});
}

 function onPhotoURISuccess(imageURI) {
    upload(imageURI);
 }


 function onFail(message) {
   alert('Failed because: ' + message);
 }

 function win(r) {

  console.log("Code = " + r.responseCode);
  console.log("Response = " + r.response);
  console.log("Sent = " + r.bytesSent);
  showProfilePage();
 }

  function fail(error) {

    alert("An error has occurred: Code = " + error.code);
    console.log("upload error source " + error.source);
    console.log("upload error target " + error.target);
  }

   function upload(imgURI) {
//var img = imgURI
//var imageURI = img.src;api/upload-image
var url = serviceURL + "api/upload-image";
var options = new FileUploadOptions();
options.fileKey = "image";

options.fileName = imgURI.substr(imgURI.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
var params = new Object();

params.user = localStorage.getItem("userId");

options.params = params;
options.chunkedMode = false;
var ft = new FileTransfer();
if (checkConnection() != 'No network connection') {
    $.mobile.loading('show');
    ft.upload(imgURI, url, win, fail,
            options);
} else {
    navigator.notification.alert(
            'Check network connection and try again!', // message
            alertDismissed, // callback
            'Network Error', // title
            'OK'                  // buttonName
            );
}

}

编辑 -

E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to resume activity {com.company.myapp/com.company.myapp.MainActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=18, result=-1, data=Intent { dat=content://media/external/images/media/12659 flg=0x1 }} to activity {com.company.myapp/com.company.myapp.MainActivity}: java.lang.NullPointerException
            at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2853)
            at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2882)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2314)
            at android.app.ActivityThread.access$700(ActivityThread.java:157)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:176)
            at android.app.ActivityThread.main(ActivityThread.java:5317)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=18, result=-1, data=Intent { dat=content://media/external/images/media/12659 flg=0x1 }} to activity {com.company.myapp/com.company.myapp.MainActivity}: java.lang.NullPointerException
            at android.app.ActivityThread.deliverResults(ActivityThread.java:3433)
            at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2827)
            at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2882)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2314)
            at android.app.ActivityThread.access$700(ActivityThread.java:157)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:176)
            at android.app.ActivityThread.main(ActivityThread.java:5317)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
            at org.apache.cordova.camera.CameraLauncher.processResultFromGallery(CameraLauncher.java:561)
            at org.apache.cordova.camera.CameraLauncher.onActivityResult(CameraLauncher.java:631)
            at org.apache.cordova.CordovaInterfaceImpl.onActivityResult(CordovaInterfaceImpl.java:120)
            at org.apache.cordova.CordovaActivity.onActivityResult(CordovaActivity.java:353)
            at android.app.Activity.dispatchActivityResult(Activity.java:5515)
            at android.app.ActivityThread.deliverResults(ActivityThread.java:3429)
            at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2827)
            at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2882)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2314)
            at android.app.ActivityThread.access$700(ActivityThread.java:157)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:176)
            at android.app.ActivityThread.main(ActivityThread.java:5317)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
            at dalvik.system.NativeStart.main(Native Method)
4

0 回答 0