android - Opening gallery as app programmatically -


i want open gallery when user presses button. code use this:

intent resimgaleri = new intent(); resimgaleri.settype("image/*"); resimgaleri.setflags(intent.flag_activity_new_task); main.this.startactivity(resimgaleri); 

however, in code, when user presses button open gallery, android asks 'complete action using', want open gallery directly without asking. can following code:

startactivity(new intent("com.android.gallery3d")); 

but i'm not sure if all devices use 'com.android.gallery3d' or not. possible or there other way that?

not devices have com.android.gallery3d, while of them do. can query package manager intent action view mime type image/* list of activities. , through list find correct one.

final intent = new intent(intent.action_view, null); i.settype("image/*"); final list<resolveinfo> apps = packagemanager.queryintentactivities(i, 0); if(apps != null) {     for(resolveinfo info : apps) {         if(info.resolvepackagename!=null && info.resolvepackagename.contains("gallery3d")) {//maybe use more strict condition              //this target want              //startactivity(xxxx);              return;         }     }     //target not found     //start first match or handle exception here } else { //handle exception } 

Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -