When you create an Android application to download a PDF file from internet, you might want to view the file after download completed. In the tip download progress dialog, I showed you how to download a file from internet and display a progress dialog to show the percentage of downloading task. In this tip, I will show you how to view or open the PDF file stored in your phone's external storage.
public void onStart(){
super.onStart();
String path=Environment.getExternalStorageDirectory()+"/edoc_download/Moi201.pdf";
File file = new File(path);
Intent target = new Intent(Intent.ACTION_VIEW);
target.setDataAndType(Uri.fromFile(file),"application/pdf");
target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
Intent intent = Intent.createChooser(target, "Open File");
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
// Instruct the user to install a PDF reader here, or something
}
}
Posted by: Dara | post date: 05-31-2014 | Subject: Android Apps Development
|
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.