// File indicates the file path.
Private void openfile (File file ){
Intent intent = new intent ();
Intent. addflags (intent. flag_activity_new_task );
// Set the intent action attribute
Intent. setaction (intent. action_view );
// Obtain the MIME type of the file
String type = getmimetype (File );
// Set the data and type attributes of intent.
Intent. setdataandtype (URI. fromfile (file), type );
// Jump
Startactivity (intent );
}
// Method for Determining the file mimetype
Private string getmimetype (file F ){
String type = "";
String fname = f. getname ();
// Get the extension
String end = fname. substring (fname. lastindexof (".") + 1, fname. Length (). tolowercase ());
// Determine the MIME type based on the extension
If (end. equals ("m4a") | end. equals ("MP3") | end. equals ("mid") | end. equals ("xmf") | end. equals ("Ogg") | end. equals ("WAV ")){
Type = "audio ";}
Else if (end. Equals ("3GP") | end. Equals ("MP4 ")){
Type = "video ";
}
Else if (end. equals ("jpg") | end. equals ("GIF") | end. equals ("PNG") | end. equals ("Jpeg") | end. equals ("BMP ")){
Type = "image ";
}
Else if (end. Equals ("APK ")){
// Open the APK installation program and register Android. Permission. install_packages in androidmanifest.
Type = "application/vnd. Android. Package-Archive ";
}
Return type;
}