Accessing Android native gallery via an intent -
how can user select native gallery in android, rather other gallery-like applications such astro file manager?
the following code gives list of activities can select image:
intent intent = new intent(); intent.settype("image/*"); intent.setaction(intent.action_get_content); list<resolveinfo> infos = activity.getpackagemanager().queryintentactivities(intent, 0);
if this:
activity.startactivityforresult(intent.createchooser(intent, "select picture"), request_choose_image);
then if user has more 1 application can act gallery (such astro file manager), s/he prompted select 1 of them, no "set default" option.
i don't want user prompted choose between them each time, i'd use native gallery.
the hacky code sample below uses whitelist test known native gallery names:
(resolveinfo info : infos) { if ( 0==info.activityinfo.name.compareto("com.cooliris.media.gallery") || 0==info.activityinfo.name.compareto("com.htc.album.collectionsactivity") ) { // found native gallery dosomethingwithnativegallery(); } }
feels kinda dirty. there better way? suspect i'm missing in intent.
i didn't last part of code.
to start native gallry did -
public void upload(){ intent photopickerintent = new intent(intent.action_get_content); photopickerintent.settype("image/jpg"); photopickerintent.putextra(intent.extra_stream, uri.parse("file:///sdcard/pictures/image.jpg")); startactivityforresult(photopickerintent, 1); }
call upload() start native gallery.
then image info did -
/** * retrieves returned image intent, inserts mediastore, * automatically saves thumbnail. assigns thumbnail imageview. * @param requestcode sub-activity code * @param resultcode specifies whether activity cancelled or not * @param intent data packet passed sub-activity */ @override protected void onactivityresult(int requestcode, int resultcode, intent intent) { super.onactivityresult(requestcode, resultcode, intent); if (resultcode == result_canceled) { return; } else if(resultcode == result_ok) { uri uri = intent.getdata(); string path = getpath(uri); log.i("path", path); data = path; return; } uplad(); } public string getpath(uri uri) { string[] projection = { mediastore.images.media.data }; cursor cursor = managedquery(uri, projection, null, null, null); int column_index = cursor .getcolumnindexorthrow(mediastore.images.media.data); cursor.movetofirst(); return cursor.getstring(column_index); }
if wouldn't answer, clear do
Comments
Post a Comment