• Advertisement
Sign in to follow this  

Android Intent - How can i open file

This topic is 2039 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello!

To open image or sound we can use this code:
[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);[/code]

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 ?

Share this post


Link to post
Share on other sites
Advertisement
Have you carefully [url="http://developer.android.com/guide/topics/intents/intents-filters.html"]read the manual[/url] on how to do this? You need to make sure your manifest file is correct. If your file is not correct your app will crash, as described.


Also, If you know about the apps why not specify them by name?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement