To open image or sound we can use this code:
public String getExt(String filename){
int dotIndex = 0;
for(int i = filename.length()-1; i >= 0; i--)
{
if(filename.charAt(i) == '.') {
dotIndex = i;
break;
}
}
return filename.substring(dotIndex + 1, filename.length());
}
public String getTypeAction(String s) {
int slashIndex = 0;
for(int i = 0; i < s.length(); i++)
{
if(s.charAt(i) == '/') {
slashIndex = i;
break;
}
}
return s.substring(0, slashIndex);
}
//////
//////
MimeTypeMap mime = MimeTypeMap.getSingleton();
String ext = getExt(file_to_action.getName());
ext = ext.toLowerCase();
String type = mime.getMimeTypeFromExtension(ext);
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file_to_action), getTypeAction(type) + "/*" );
startActivity(intent);
But the problem is when i want to open any different file for example: .mhtml, .bak. apk. When i do this my application is crash. I don't know where is the problem, i have application for .mhtml, .odt extenio but my application can't use this applications to open the file.
How i can open all file format or how i can check avaliable application for any file format ?