我使用此代码通过我的应用程序打开了Gallery应用程序 -
Intent galleryIntent = new Intent(Intent.ACTION_VIEW, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
galleryIntent.setType("image/*");
startActivity(galleryIntent);
当我选择"打开图库"时,图库应用程序在OnePlus One设备上与此堆栈跟踪崩溃 -
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cyngn.gallerynext/com.cyngn.gallerynext.app.fullscreenviewer.FullscreenViewer}: java.lang.NullPointerException: uriString
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2420)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Caused by: java.lang.NullPointerException: uriString
at android.net.Uri$StringUri.<init>(Uri.java:470)
at android.net.Uri$StringUri.<init>(Uri.java:460)
at android.net.Uri.parse(Uri.java:432)
at com.cyngn.gallerynext.app.fullscreenviewer.FullscreenViewer.a(SourceFile:305)
at com.cyngn.gallerynext.app.fullscreenviewer.FullscreenViewer.onCreate(SourceFile:217)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2420)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
我不想将特定的URI传递给它,我只是想让它打开默认的图库文件夹。我该如何避免这次崩溃?
答案 0 :(得分:1)
不使用setType("image/*")
Intent galleryIntent = new Intent(Intent.ACTION_VIEW, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivity(galleryIntent);
yourIntent.setType(String mimeType)
这表示您想要获取的MIME类型数据。使用android.provider.MediaStore.Images.Media
您有常量MIME。我想,在这里您可以找到更多docs
答案 1 :(得分:0)
如果您想仅打开应用(因为您写道:我只是想让它打开默认的图库文件夹):
Intent intent = new Intent("com.cyngn.gallerynext");
或
如果您想从图库see this post how to do it获取任何数据。