我試圖打開內置圖庫應用程序在我的應用程序中按下按鈕。在Android中打開圖庫應用程序
我嘗試了Android 2.3及以上版本的手機。在手機/平板電腦,我有是
三星S(的Android 2.3.5) LG手機(安卓2.3.3) 歌Nexus One(Android的2.3.6) Android平板電腦(安卓4.0.3) 的Galaxy Nexus (安卓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);
同樣,這只是正常與高於/ equalto 4.0版本的手機。在4.0以下的手機,它通過說:
"No application can perform this action"
有人可以幫我打開圖庫從我的應用程序按下按鈕?
也許這樣。 http://stackoverflow.com/questions/6016000/how-to-open-phones-gallery-through-code –