Android在Android画廊中打开特定的imege

时间:2013-08-12 09:28:50

标签: android image image-gallery

我已经得到并保存了存储在图库中的图像的uri,然后我想打开那些图像 再次与画廊。

我正在使用这个意图......但我得到空指针......

public void vedifoto(View view) {
    int i = mViewPager.getCurrentItem();
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.parse(foto[i]), "image/*");
    startActivity(intent);
}

错误堆栈:

08-12 09:33:35.669: E/AndroidRuntime(1012): FATAL EXCEPTION: main
08-12 09:33:35.669: E/AndroidRuntime(1012): java.lang.RuntimeException: Unable to start    activity ComponentInfo{com.android.gallery/com.android.camera.ViewImage}: java.lang.NullPointerException
08-12 09:33:35.669: E/AndroidRuntime(1012):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at android.os.Looper.loop(Looper.java:137)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at android.app.ActivityThread.main(ActivityThread.java:5041)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at java.lang.reflect.Method.invokeNative(Native Method)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at java.lang.reflect.Method.invoke(Method.java:511)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at dalvik.system.NativeStart.main(Native Method)
08-12 09:33:35.669: E/AndroidRuntime(1012): Caused by: java.lang.NullPointerException
08-12 09:33:35.669: E/AndroidRuntime(1012):     at com.android.camera.MenuHelper.isWhiteListUri(MenuHelper.java:151)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at com.android.camera.ViewImage.onCreate(ViewImage.java:617)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at android.app.Activity.performCreate(Activity.java:5104)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
08-12 09:33:35.669: E/AndroidRuntime(1012):     ... 11 more

foto是我在照片库中的照片的路径,我将其用作按钮图像,并且当用户点击它时我需要在图库中查看该图像。

1 个答案:

答案 0 :(得分:0)

使用此代码

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + "/sdcard/test.jpg"), "image/*");
startActivity(intent);

您需要指定正确的路径......