在Android中打开Gallery App [英] Open Gallery App in Android

查看:218
本文介绍了在Android中打开Gallery App的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按下我的应用中的按钮打开内置的图库应用。

I am trying to open inbuilt gallery app pressing a button in my app.

我正在试用Android 2.3及以上的手机。我拥有的手机/平板电脑

I am trying out on Android 2.3 and above phones. The phones/tablet that I have are

三星S(Android 2.3.5)
LG手机(Android 2.3.3)
Nexus One( Android 2.3.6)
Android平板电脑(Android 4.0.3)
Galaxy Nexus(Android 4.3)

Samsung S (Android 2.3.5) LG phone (Android 2.3.3) Nexus One (Android 2.3.6) Android Tablet (Android 4.0.3) Galaxy Nexus (Android 4.3)

我尝试了以下内容:

Intent intent = new Intent(Intent.ACTION_VIEW, null);
intent.setType("image/*");
startActivity(intent); 

以上代码在Android平板电脑(4.0.3)和我的Nexus手机上运行良好..但如果在任何低于3.0的手机上运行相同的应用程序(给我错误)

above code works fine on Android tablet (4.0.3) and my Nexus phone too.. but if run the same app on any phone which is below 3.0 (gives me error)

08-24 11:47:53.628: E/AndroidRuntime(787):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
08-24 11:47:53.628: E/AndroidRuntime(787):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
08-24 11:47:53.628: E/AndroidRuntime(787):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-24 11:47:53.628: E/AndroidRuntime(787):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
08-24 11:47:53.628: E/AndroidRuntime(787):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-24 11:47:53.628: E/AndroidRuntime(787):  at android.os.Looper.loop(Looper.java:130)
08-24 11:47:53.628: E/AndroidRuntime(787):  at android.app.ActivityThread.main(ActivityThread.java:3687)
08-24 11:47:53.628: E/AndroidRuntime(787):  at java.lang.reflect.Method.invokeNative(Native Method)
08-24 11:47:53.628: E/AndroidRuntime(787):  at java.lang.reflect.Method.invoke(Method.java:507)
08-24 11:47:53.628: E/AndroidRuntime(787):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
08-24 11:47:53.628: E/AndroidRuntime(787):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
08-24 11:47:53.628: E/AndroidRuntime(787):  at dalvik.system.NativeStart.main(Native Method)
08-24 11:47:53.628: E/AndroidRuntime(787): Caused by: java.lang.NullPointerException
08-24 11:47:53.628: E/AndroidRuntime(787):  at com.cooliris.media.Gallery.onCreate(Gallery.java:323)
08-24 11:47:53.628: E/AndroidRuntime(787):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-24 11:47:53.628: E/AndroidRuntime(787):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
08-24 11:47:53.628: E/AndroidRuntime(787):  ... 11 more

所以我尝试了以下内容:

So I tried the following:

Intent intent1= new Intent("android.intent.action.MAIN", null);
intent1.addCategory("android.intent.category.APP_GALLERY");
Intent intent2 = Intent.createChooser(intent1, "Gallery");
startActivity(intent2);

同样适用于高于/等于4.0版本的手机。在4.0以下的手机上,它通过以下方式发出警报通知:

Again this works just fine with phones that are above/equalto 4.0 version. On 4.0 below phones it gives alert notification by saying:

"No application can perform this action"

有人可以通过按我的应用程序中的按钮来帮助我打开图库吗?

Can somebody help me out with opening the Gallery from pressing a button from my app?

推荐答案

我想通了..

 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(
 "content://media/internal/images/media")); 
 startActivity(intent); 

这条代码刚刚打开了库,没有任何问题。可以让它适用于所有版本!

This piece of code just opened the gallery without any issues. Could get it working on all versions!

想把它作为想要在所有版本上打开图库的人的答案。

Thought to put it as answer for people who are looking to open a Gallery on all versions.

谢谢大家! :)

这篇关于在Android中打开Gallery App的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆