Intent How can i open file

Put your problem here if it does not fit any of the other categories.

Intent How can i open file

Postby adrian_134 » Wed Jun 20, 2012 4:12 am

Hello!

To open image or sound we can use this code:
Code: Select all
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 ?
adrian_134
Freshman
Freshman
 
Posts: 7
Joined: Sun Oct 16, 2011 1:02 pm

Top

Re: Intent How can i open file

Postby DeK » Thu Jun 21, 2012 5:03 pm

Is this the piece of code which crashes? Otherwise, please provide the relevant method and the stack trace you get when the error occurs
DeK
Freshman
Freshman
 
Posts: 2
Joined: Thu Jun 21, 2012 3:29 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 17 guests