Matches the file suffix name MIME type.
1 ImportJava.io.File;2 3 ImportAndroid.content.Context;4 Importandroid.content.Intent;5 ImportAndroid.net.Uri;6 7 Public classOpenfileutil {8 9 Public Static Finalstring[][] Mime_maptable = {Ten //{suffix name, MIME type} One{". 3gp", "VIDEO/3GPP" }, A{". apk", "application/vnd.android.package-archive" }, -{". asf", "VIDEO/X-MS-ASF" }, -{". avi", "Video/x-msvideo" }, the{". Bin", "Application/octet-stream" }, -{". bmp", "Image/bmp" }, -{". C", "Text/plain" }, -{". Class", "Application/octet-stream" }, +{". conf", "Text/plain" }, -{". cpp", "Text/plain" }, +{". doc", "Application/msword" }, A{". docx", at"Application/vnd.openxmlformats-officedocument.wordprocessingml.document" }, -{". xls", "application/vnd.ms-excel" }, -{". xlsx", -"Application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }, -{". exe", "Application/octet-stream" }, -{". gif", "Image/gif" }, in{". Gtar", "Application/x-gtar" }, -{". Gz", "Application/x-gzip" }, to{". h", "Text/plain" }, +{". htm", "text/html" }, -{". html", "text/html" }, the{". Jar", "application/java-archive" }, *{". Java", "Text/plain" }, ${". jpeg", "image/jpeg" },Panax Notoginseng{". jpg", "image/jpeg" }, -{". js", "Application/x-javascript" }, the{". Log", "Text/plain" }, +{". m3u", "Audio/x-mpegurl" }, A{". m4a", "AUDIO/MP4A-LATM" }, the{". m4b", "AUDIO/MP4A-LATM" }, +{". m4p", "AUDIO/MP4A-LATM" }, -{". M4u", "Video/vnd.mpegurl" }, ${". m4v", "VIDEO/X-M4V" }, ${". mov", "video/quicktime" }, -{". Mp2", "Audio/x-mpeg" }, -{". mp3", "Audio/x-mpeg" }, the{". mp4", "Video/mp4" }, -{". MPC", "Application/vnd.mpohun.certificate" },Wuyi{". Mpe", "Video/mpeg" }, the{". mpeg", "Video/mpeg" }, -{". mpg", "video/mpeg" }, Wu{". Mpg4", "Video/mp4" }, -{". MPGA", "Audio/mpeg" }, About{". Msg", "Application/vnd.ms-outlook" }, ${". ogg", "Audio/ogg" }, -{". pdf", "Application/pdf" }, -{". png", "Image/png" }, -{". pps", "Application/vnd.ms-powerpoint" }, A{". ppt", "Application/vnd.ms-powerpoint" }, +{". pptx", the"Application/vnd.openxmlformats-officedocument.presentationml.presentation" }, -{". Prop", "Text/plain"}, {". rc", "Text/plain" }, ${". rmvb", "Audio/x-pn-realaudio"}, {". rtf", "Application/rtf" }, the{". Sh", "Text/plain"}, {". Tar", "Application/x-tar" }, the{". tgz", "application/x-compressed"}, {". txt", "Text/plain" }, the{". wav", "Audio/x-wav"}, {". wma", "AUDIO/X-MS-WMA" }, the{". wmv", "audio/x-ms-wmv" }, -{". wps", "Application/vnd.ms-works"}, {". xml", "Text/plain" }, in{". Z", "application/x-compress" }, the{". zip", "application/x-zip-compressed"}, {"", "*/*" } }; the About /** the * Open File the * the * @paramfile + */ - Public Static voidopenFile (file file, context context) { the BayiIntent Intent =NewIntent (); the intent.addflags (intent.flag_activity_new_task); the //set the Action property of Intent - intent.setaction (intent.action_view); - //gets the MIME type of file files theString type =getmimetype (file); the //sets the data and Type properties of the intent. theIntent.setdataandtype (/*URI*/uri.fromfile (file), type); the //Jump - context.startactivity (intent); the the } the 94 /** the * @paramfile the * @returnget the file suffix name the */98 Private StaticString getmimetype (file file) { AboutString type = "*/*"; -String FName =file.getname ();101 //gets the delimiter "." Before the suffix name. The position in the fname. 102 intDotindex = Fname.lastindexof ("."));103 if(Dotindex < 0) {104 returntype; the }106 /*gets the suffix name of the file*/107String end =fname.substring (Dotindex, Fname.length ()). toLowerCase ();108 if(end = "")109 returntype; the //The corresponding MIME type is found in the matching table of mime and file types. 111 for(inti = 0; i < mime_maptable.length; i++) {//mime_maptable?? You must have a question here, what is this mime_maptable? the if(End.equals (mime_maptable[i][0]))113Type = mime_maptable[i][1]; the } the returntype; the }117 118}
Android development tool Class 34_openfileutil