2013-06-04 87 views
1

我是Android和开发世界的新手。 (场景如下)PDF在android中的渲染

我创建了一个使用HTML5和CSS的android应用程序,并使用phonegap将其捆绑出来。 现在我需要有两个选项供用户先下载,然后是否读或第二在线阅读

所以我的问题是,我不能够dispaly PDF显示PDF文件在此应用程序在应用中。 我怎么能做到这一点?请帮忙 。我试图从最后4天解决它,并尝试了每个已经在论坛上给出的解决方案,但仍然没有成功。

对我来说,如果有人一步一步地或一个例子参考,那将会很棒。

谢谢 单宝元

回答

0

试试这个代码

private void openBook() { 
    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(); 
    } 
} 
0

您可以通过故意打开PDF文件这样

File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/example.pdf"); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file),”application/pdf”); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); startActivity(intent);