Open the suffix. apk file, that is, start the installer;
Apkfilepath file path public void installapk (String apkfilepath) { //create URI uri uri = uri.fromfile (new file Apkfilepath)); Intent Intent = new Intent (intent.action_view); Set the URI and type intent.setdataandtype (URI, "application/vnd.android.package-archive"); Perform installation mcontext.startactivity (intent); }
/** * Open multiple types of files * @param path file paths * @param type file type */public void OpenText (String path, int type) {Intent Intent = New Intent (Intent.action_view); Intent.addcategory (Intent.category_default); Intent.addflags (Intent.flag_activity_new_task); Uri uri = uri.fromfile (new File); Determine the file type if (file_type_ppt = = type) {Intent.setdataandtype (URI, "Application/vnd.ms-powerpoint"); } else if (File_type_word = = TYPE) {intent.setdataandtype (URI, "Application/msword"); } else if (File_type_excel = = TYPE) {intent.setdataandtype (URI, "application/vnd.ms-excel"); } else if (file_type_txt = = TYPE) {intent.setdataandtype (URI, "Text/plain"); } else if (file_type_pdf = = TYPE) {intent.setdataandtype (URI, "application/pdf"); } else if (file_type_html = = TYPE) {Uri Htmluri = uri.parse (path). Buildupon (). encodedauthority ("com. Android.htmlfileprovider "). Scheme (" Content "). Encodedpath (Path). build (); Intent.setdataandtype (Htmluri, "text/html"); } try {activity.startactivity (intent); } catch (Exception e) {toast.maketext (Mcontext, "The program that supports this format is not installed in the device", Toast.length_short). Show (); }}
<pre name= "code" class= "Java" >////////open multimedia type Intent.setdataandtype (URI, "audio/*"); Audio Intent.setdataandtype (URI, "video/*"); Video Intent.setdataandtype (URI, "image/*"); Picture Intent.setdataandtype (URI, "Application/x-chm"); Open CHM File
Determines whether the file name is a suffix of some kind private Boolean check (final String name, Final string[] extensions) {for (string end:extensions) {if (Name.tolowercase (). EndsWith (end)) {return true;}} return false;} Set the type if (check (name, ". apk")) { file.settype (file_type_apk); } else if (check (name, ". PDF ")) { file.settype (file_type_pdf); } else if (check (name, Getstringarray (r.array.ppt_filter))) { File.settype (file_type_ppt); } ..... array.ppt_filter:<array name= "Ppt_filter" > <item>.ppt</item> <------ Item>.pptx</item> </array>
Get device Storage path (SD card, USB)
Environment.getexternalstoragedirectory ();
Environment.getexternalstoragedirectory (). GetParent ();