Open special folder view intent in old version of android -
i'm trying open special folder user can pick .xml file. , user setdataandtype intent . works fine in new versions of android (tested api 21.. 25). doesn't work api 16. here code use:
var intent = new intent(); android.net.uri contenturi = null; if (_existingconfig != null) { if (requestcode == assets_select_code && !string.isnullorempty(_existingconfig.assetspath)) { contenturi = android.net.uri.fromfile(new java.io.file(_existingconfig.assetspath)); } else if (!string.isnullorempty(_existingconfig.goodspath)) { contenturi = android.net.uri.fromfile(new java.io.file(_existingconfig.goodspath)); } } if (contenturi != null) { intent.setdataandtype(contenturi, "text/xml"); } else { intent.settype("text/xml"); } if (build.version.sdkint < buildversioncodes.kitkat) { intent.setaction(intent.actiongetcontent); startactivityforresult(intent.createchooser(intent, resources.getstring(resource.string.select_xml_file)), requestcode); } else { intent.setaction(intent.actionopendocument); startactivityforresult(intent, requestcode); }
the same window shown every time
try this
string path = "your path"; intent intent = new intent(intent.action_view); intent.setdataandtype(getfileuri(path.trim()), getmimetype(path.trim())); intent.addflags(intent.flag_activity_clear_task); startactivity(intent); /** * determine mime type document file * * @param url complete path of file * @return string type of mime */ private static string getmimetype(string url) { string type = null; string extension = mimetypemap.getfileextensionfromurl(url); if (extension != null) { type = mimetypemap.getsingleton().getmimetypefromextension(extension); } return type; } /** * generate uri required intent * * @param filepath path of required file * @return uri */ private static uri getfileuri(string filepath) { uri fileuri = null; file file = new file(filepath); try { if (build.version.sdk_int >= build_version) { method m = strictmode.class.getmethod("disabledeathonfileuriexposure"); m.invoke(null); } fileuri = uri.fromfile(file); } catch (exception e) { e.printstacktrace(); } return fileuri; }
Comments
Post a Comment