在线(互联网连接)以及离线模式的PDF查看器

kam*_*iew 2 android

PDF内容可以是在线模式也可以是离线模式,我需要在我自己的自定义布局中显示pdf,因此无法使用Intent.任何建议将不胜感激.谢谢.

Dyn*_*ind 5

是的,我们可以在google doc api的帮助下在线上显示pdf内容.这里我给出了使用它的代码.用于ON线模式

public class ReaderActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

   WebView webView=(WebView)this.findViewById(R.id.WebView01);
        Intent intent = new Intent(Intent.ACTION_VIEW);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setAllowFileAccess(true);
        webView.getSettings().setPluginsEnabled(true);
        webView.loadUrl("https://docs.google.com/viewer?url=http%3A%2F%2Fwww.eli.sdsu.edu%2Fcourses%2Ffall09%2Fcs696%2Fnotes%2FAndroid13Web.pdf");
        //intent.setDataAndType(Uri.parse("https://docs.google.com/viewer?url=---------Your URL");

       }}
Run Code Online (Sandbox Code Playgroud)

用于OFF线模式

        File file = new File(mRealPath);
        Uri path = Uri.fromFile(file);
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.setDataAndType(path, getString(R.string.application_type));
        try 
        {
            startActivity(intent);
        } 
        catch (ActivityNotFoundException e) 
        {
            Toast.makeText(FirstTab.this, 
                getString(R.string.no_application_found), 
                Toast.LENGTH_SHORT).show();
        }
Run Code Online (Sandbox Code Playgroud)

注意:在离线模式下,首先你有下载文件格式服务器到sd-card中的本地设备这个文件的获取路径并把它放在路径变量的位置然后你得到你的洞问题的答案.

在此代码中,您应该在我的网址中使用您的网址.我希望这是有帮助的.