Dear all
Welcome to my blog android rocks, in this post we will see how to open different different files with default application using intents.
Below the code snippets
1. Opening Mp4 Files (Video)
Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); File file = new File("/sdcard/test.mp4"); intent.setDataAndType(Uri.fromFile(file), "video/*"); startActivity(intent);
2. Opening Mp3 Files (Audio)
Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); File file = new File("/sdcard/test.mp3"); intent.setDataAndType(Uri.fromFile(file), "audio/*"); startActivity(intent);
3. Opening HTML Files
Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); File file = new File("/sdcard/readme.html"); intent.setDataAndType(Uri.fromFile(file), "text/html");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent);
4. Opening PDF Files
Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); File file = new File("/sdcard/readme.html"); intent.setDataAndType(Uri.fromFile(file), "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent);
Thanks......
No comments:
Post a Comment