来自图库错误的Android图片选择器

时间:2014-04-09 13:55:49

标签: android image gallery android-gallery

当我从我的图库中选择图像时遇到此问题。 由于某种原因,它不适用于我的手机(Galaxy s3,4.4.2),但在其他设备上工作正常(其中一个是Galaxy s3 4.2.2)。 在我最明显的文件中,目标是19。 这是日志:

  

04-09 16:46:55.040:E / AndroidRuntime(11186):致命异常:主要   04-09 16:46:55.040:E / AndroidRuntime(11186):进程:com.appgate.homeland,PID:11186   04-09 16:46:55.040:E / AndroidRuntime(11186):java.lang.RuntimeException:传递结果失败ResultInfo {who = null,request = 2002,result = -1,data = Intent {dat = content:// com.android.providers.media.documents / document / image:38468 flg = 0x1}} to activity {com.appgate.homeland / main.MainActivity}:java.lang.NullPointerException   04-09 16:46:55.040:E / AndroidRuntime(11186):在android.app.ActivityThread.deliverResults(ActivityThread.java:3385)   04-09 16:46:55.040:E / AndroidRuntime(11186):在android.app.ActivityThread.handleSendResult(ActivityThread.java:3428)   04-09 16:46:55.040:E / AndroidRuntime(11186):在android.app.ActivityThread.access $ 1300(ActivityThread.java:145)   04-09 16:46:55.040:E / AndroidRuntime(11186):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1254)   04-09 16:46:55.040:E / AndroidRuntime(11186):在android.os.Handler.dispatchMessage(Handler.java:102)   04-09 16:46:55.040:E / AndroidRuntime(11186):在android.os.Looper.loop(Looper.java:136)   04-09 16:46:55.040:E / AndroidRuntime(11186):在android.app.ActivityThread.main(ActivityThread.java:5142)   04-09 16:46:55.040:E / AndroidRuntime(11186):at java.lang.reflect.Method.invokeNative(Native Method)   04-09 16:46:55.040:E / AndroidRuntime(11186):at java.lang.reflect.Method.invoke(Method.java:515)   04-09 16:46:55.040:E / AndroidRuntime(11186):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:791)   04-09 16:46:55.040:E / AndroidRuntime(11186):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)   04-09 16:46:55.040:E / AndroidRuntime(11186):at dalvik.system.NativeStart.main(Native Method)   04-09 16:46:55.040:E / AndroidRuntime(11186):引起:java.lang.NullPointerException   04-09 16:46:55.040:E / AndroidRuntime(11186):at java.io.File.fixSlashes(File.java:185)   04-09 16:46:55.040:E / AndroidRuntime(11186):at java.io.File。(File.java:134)   04-09 16:46:55.040:E / AndroidRuntime(11186):at com.appgate.homeland.model.ImagePicker.getPathAndCopy(ImagePicker.java:147)   04-09 16:46:55.040:E / AndroidRuntime(11186):at com.appgate.homeland.model.ImagePicker.onActivityResult(ImagePicker.java:81)   04-09 16:46:55.040:E / AndroidRuntime(11186):at com.zlotindaniel.library.controller.activity.SuperActivity.onActivityResult(SuperActivity.java:262)   04-09 16:46:55.040:E / AndroidRuntime(11186):在android.app.Activity.dispatchActivityResult(Activity.java:5433)   04-09 16:46:55.040:E / AndroidRuntime(11186):在android.app.ActivityThread.deliverResults(ActivityThread.java:3381)   04-09 16:46:55.040:E / AndroidRuntime(11186):... 11更多

非常感谢!

1 个答案:

答案 0 :(得分:0)

尝试使用以下代码打开图库对话框。

    Intent intent = new Intent(Intent.ACTION_PICK,
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    intent.setType("image/*");
    // intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, "Select Photo"),
            GALLERY_PIC_REQUEST);