内容简介:翻译自:https://stackoverflow.com/questions/18416122/open-gallery-app-in-android
我正在尝试按下我的应用程序中的按钮打开内置的图库应用程序.
我正在试用Android 2.3及以上的手机.我拥有的手机/平板电脑
三星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)
我尝试了以下方法:
Intent intent = new Intent(Intent.ACTION_VIEW, null);
intent.setType("image/*");
startActivity(intent);
上面的代码在Android平板电脑(4.0.3)和我的Nexus手机上运行良好..但如果在任何低于3.0的手机上运行相同的应用程序(给我错误)
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
所以我尝试了以下内容:
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以下的手机上,它通过说:
"No application can perform this action"
有人可以帮助我从我的应用程序按下按钮打开图库吗?
我想通了……
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse( "content://media/internal/images/media")); startActivity(intent);
这条代码刚刚打开了画廊,没有任何问题.可以让它适用于所有版本!
想把它作为想要在所有版本上打开图库的人的答案.
多谢你们!
翻译自:https://stackoverflow.com/questions/18416122/open-gallery-app-in-android
以上所述就是小编给大家介绍的《java – 在Android中打开Gallery App》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- 怎样打开XML文件?xml文件如何打开?
- Android获取软键盘的高度、键盘的打开与关闭、监听键盘处于打开还是关闭状态
- php打开本地exe程序,js打开本地exe应用程序,并传递相关参数方法
- golang hijack打开方式
- 图片悬停“滑动打开”动画效果
- 网络编程——打开网络库
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Twenty Lectures on Algorithmic Game Theory
Tim Roughgarden / Cambridge University Press / 2016-8-31 / USD 34.99
Computer science and economics have engaged in a lively interaction over the past fifteen years, resulting in the new field of algorithmic game theory. Many problems that are central to modern compute......一起来看看 《Twenty Lectures on Algorithmic Game Theory》 这本书的介绍吧!