How to browse image in android app .? -


i have application running on desktop fine .there 1 button on desktop app in open gallary select image. when run app on webview happen when clcik button .? open our mobile image gallary .?

i created small open source android library project streamlines process, while providing built-in file explorer (in case user not have 1 present). it's extremely simple use, requiring few lines of code.

you can find @ github: afilechooser.

if want user able choose file in system, need include own file manager, or advise user download one. believe best can "openable" content in intent.createchooser() this:

private static final int file_select_code = 0;  private void showfilechooser() {     intent intent = new intent(intent.action_get_content);      intent.settype("*/*");      intent.addcategory(intent.category_openable);      try {         startactivityforresult(                 intent.createchooser(intent, "select file upload"),                 file_select_code);     } catch (android.content.activitynotfoundexception ex) {         // potentially direct user market dialog         toast.maketext(this, "please install file manager.",                  toast.length_short).show();     } } 

you listen selected file's uri in onactivityresult() so:

@override protected void onactivityresult(int requestcode, int resultcode, intent data) {     switch (requestcode) {         case file_select_code:         if (resultcode == result_ok) {             // uri of selected file              uri uri = data.getdata();             log.d(tag, "file uri: " + uri.tostring());             // path             string path = fileutils.getpath(this, uri);             log.d(tag, "file path: " + path);             // file instance             // file file = new file(path);             // initiate upload         }         break;     }     super.onactivityresult(requestcode, resultcode, data); } 

the getpath() method in fileutils.java is:

public static string getpath(context context, uri uri) throws urisyntaxexception {     if ("content".equalsignorecase(uri.getscheme())) {         string[] projection = { "_data" };         cursor cursor = null;          try {             cursor = context.getcontentresolver().query(uri, projection, null, null, null);             int column_index = cursor.getcolumnindexorthrow("_data");             if (cursor.movetofirst()) {                 return cursor.getstring(column_index);             }         } catch (exception e) {             // eat         }     }     else if ("file".equalsignorecase(uri.getscheme())) {         return uri.getpath();     }      return null; }  

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -