How to open PDF in Android

后端 未结 3 1749
醉话见心
醉话见心 2021-02-01 11:21

How to open pdf file from server without saving it on device and without using any third party application.because i don\'t want my user to download any application to use my ap

3条回答
  •  独厮守ぢ
    2021-02-01 11:54

    This method worked in the older versions of android:

    In a new activity:

            WebView webview = new WebView(this);
            setContentView(webview);
            webview.getSettings().setJavaScriptEnabled(true);
            webview.getSettings().setPluginsEnabled(true);
            webview.loadUrl("http://docs.google.com/gview?embedded=true&url=URL_of_PDF/fileName.pdf");
            setContentView(webview);
    

    give internet permission in manifest file.

    USE the following method to open a PDF file with already installed 3rd party application.

    To open the PDF in application use:

    Uri path = Uri.fromFile(file);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(path, "application/pdf");
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);
    

提交回复
热议问题