Opening pdf file programmatically is going into menu page?

前端 未结 2 683
野趣味
野趣味 2021-01-07 13:40

How come every time i try to open a pdf file in my SDCARD using the following code, it doesn\'t actually open the pdf file itself, but goes into the menu of adobe reader? Is

2条回答
  •  甜味超标
    2021-01-07 14:20

    No, there's nothing wrong. You've set the type to pdf and specified the package as adobe.reader. What that does is fire off an intent to launch the pdf in adobe reader. There's no way to display a pdf directly in your app without using a library (or writing code yourself) to render PDFs and display them.

    Note that if you only set the type and not the package, the system will find whatever app is available to display PDFs

    EDIT

    You can try something like

        Intent intent = new Intent(Intent.ACTION_VIEW);
        File file = new File( filename  );
        intent.setDataAndType( Uri.fromFile( file ), "application/pdf" );
        startActivity(intent);
    

    or

            Intent intent = new Intent();
            intent.setPackage("com.adobe.reader");
            intent.setDataAndType(Uri.fromFile(file), "application/pdf");
            startActivity(intent);
    

提交回复
热议问题