开发者

How to open PDF file in android emulator

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();
                }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜