【发布时间】:2012-10-24 13:55:20
【问题描述】:
我在一个应用程序上使用 PhoneGap + Sencha Touch。我设法拍照并上传到服务器。我在从照片库中选择图片时遇到问题。
selectPicture: function () {
navigator.camera.getPicture(this.uploadPicture.bind(this), this.getPictureError.bind(this), {
// camera options
quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
});
}
我认为destinationType 属性有问题。在我的 uploadPicture 函数中,imageURI 返回一个目录,如:'content://media/external/images/media/[一些随机数]'。
我认为 imageURI 应该类似于:'file://storage/sdcard/DCIM/Camera/myimage.jpg'
我尝试使用 window.resolveLocalFileSystemURI,如果您正在拍照,它可以正常工作,但在选择图片时却不行。这是我想从照片库中选择图片时的代码(我正在使用 sencha touch 2):
selectPicture: function () {
navigator.camera.getPicture(this.resolveFileURI.bind(this), this.getPictureError.bind(this), {
// camera options
quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
});
},
resolveFileURI: function (entry) {
console.log(entry);
window.resolveLocalFileSystemURI(entry, this.uploadPicture.bind(this), this.fail.bind(this));
},
uploadPicture: function (entry) {
console.log(entry.fullPath)
}
根据 logcat,我什至没有将其放入 resolveFileURI 函数中。事实上,我的应用程序崩溃了。 logcat中的错误是:
10-23 14:39:24.552:E/AndroidRuntime(2975):致命异常:主要 10-23 14:39:24.552: E/AndroidRuntime(2975): java.lang.RuntimeException: 传递结果失败 ResultInfo{who=null, request=17, result=-1, data=Intent { dat=content:// media/external/images/media/584 }} 到活动 {com.dwmobile.android/com.dwmobile.android.AndroidSencha}:java.lang.NullPointerException 10-23 14:39:24.552: E/AndroidRuntime(2975): 在 android.app.ActivityThread.deliverResults(ActivityThread.java:3141) 10-23 14:39:24.552: E/AndroidRuntime(2975): 在 android.app.ActivityThread.handleSendResult(ActivityThread.java:3184) 10-23 14:39:24.552: E/AndroidRuntime(2975): 在 android.app.ActivityThread.access$1100(ActivityThread.java:130) 10-23 14:39:24.552: E/AndroidRuntime(2975): 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243) 10-23 14:39:24.552: E/AndroidRuntime(2975): 在 android.os.Handler.dispatchMessage(Handler.java:99) 10-23 14:39:24.552: E/AndroidRuntime(2975): 在 android.os.Looper.loop(Looper.java:137) 10-23 14:39:24.552: E/AndroidRuntime(2975): 在 android.app.ActivityThread.main(ActivityThread.java:4745) 10-23 14:39:24.552: E/AndroidRuntime(2975): 在 java.lang.reflect.Method.invokeNative(Native Method) 10-23 14:39:24.552: E/AndroidRuntime(2975): 在 java.lang.reflect.Method.invoke(Method.java:511) 10-23 14:39:24.552: E/AndroidRuntime(2975): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 10-23 14:39:24.552: E/AndroidRuntime(2975): 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 10-23 14:39:24.552: E/AndroidRuntime(2975): 在 dalvik.system.NativeStart.main(Native Method) 10-23 14:39:24.552:E/AndroidRuntime(2975):原因:java.lang.NullPointerException 10-23 14:39:24.552: E/AndroidRuntime(2975): 在 org.apache.cordova.CameraLauncher.onActivityResult(CameraLauncher.java:453) 10-23 14:39:24.552: E/AndroidRuntime(2975): 在 org.apache.cordova.DroidGap.onActivityResult(DroidGap.java:823) 10-23 14:39:24.552: E/AndroidRuntime(2975): 在 android.app.Activity.dispatchActivityResult(Activity.java:5192) 10-23 14:39:24.552: E/AndroidRuntime(2975): 在 android.app.ActivityThread.deliverResults(ActivityThread.java:3137)
【问题讨论】:
-
确保 phonegap 工作正常?
-
Phonegap 工作正常。我在我的应用程序中到处使用phonegap,这是它不起作用的地方。我也可以拍照上传就好了。当我从照片库中选择一张图片时,我就会遇到麻烦。
-
尝试更改phonegap版本。我的应用使用 sencha touch 2 和 phonegap 1.5。它适用于 camare 和 library。
-
您使用的是哪个版本的 PhoneGap?
-
cordova-2.0.0 是版本。