简体   繁体   English

Android在Android Gallery中打开特定的Imege

[英]Android open specific imege in android gallery

i have getted and saved the uri of an image stored in gallery, then I want to open that images with gallery again. 我已经获取并保存了存储在图库中的图像的uri,然后我想再次使用图库打开该图像。

i'm using this intent...but i get null pointer... 我正在使用这个意图...但是我得到了空指针...

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);
}

Error stack: 错误堆栈:

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 is the path of my photo in gallery, i use it as button image, and it work, when user click on it i need to view that image in the gallery. foto是我的照片在图库中的路径,我将其用作按钮图像,并且可以正常工作,当用户单击它时,我需要在图库中查看该图像。

Use This Codes 使用此代码

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

You need to specify the correct path... 您需要指定正确的路径...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM