Pages

Sunday, July 31, 2011

Opening a File Using Default Application in Android


Opening a File Using Default Application in Android
Here is the  code to do this


File file = new File("direcotry","fileName");
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "mimetype");
startActivity(intent); 

if you want to open a audio file code would look something similar to the following


File file = new File("direcotry","fileName");
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent); 



using setDataAndType method would allow you to over rule the actual mime type of the file.