Jump to content

  • Log In with Google      Sign In   
  • Create Account


Android Intent - How can i open file


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 adrian_134   Members   -  Reputation: 120

Like
0Likes
Like

Posted 20 June 2012 - 01:53 AM

Hello!

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 ?

Sponsor:

#2 frob   Moderators   -  Reputation: 16203

Like
0Likes
Like

Posted 20 June 2012 - 09:24 AM

Have you carefully read the manual 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?
Check out my personal indie blog at bryanwagstaff.com.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS