开发者

How to open PDF file in android emulator

开发者 https://www.devze.com 2023-04-07 18:26 出处:网络
I would like to know how to open a PDF file? What all changes do we need to make in the manifest file.

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

精彩评论

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

关注公众号