I would like to know how to open a PDF file? What all changes do we need to make in the manifest file. Can I open it in a browser? What all 开发者_StackOverflow中文版permissions would be required for it?
If there is an application installed that handles the application/pdf mime type then you can open it. You cannot specify that it only be opened in browser unless browser is the only application that handles it. Following is the code snippet for opening a pdf file
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
}
catch (ActivityNotFoundException e) {
Toast.makeText(OpenPdf.this,
"No Application Available to View PDF",
Toast.LENGTH_SHORT).show();
}
精彩评论