android中打开pdf,在Android应用程序中打开PDF

我正在开发应用程序,需要在设备中打开pdf文件,

我实际上已经获得了与大多数示例类似的网络上的代码。但是,事情是我无法打开文件,控件直接转到“Exception”部分。

以下是以下代码:

public class MyPDFDemo extends Activity

{

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Button OpenPDF = (Button) findViewById(R.id.button);

OpenPDF.setOnClickListener(new View.OnClickListener()

{

public void onClick(View v)

{

File pdfFile = new File("/sdcard/Determine_RGB_Codes_With_Powerpoint [PDF Library].pdf");

if(pdfFile.exists())

{

Uri path = Uri.fromFile(pdfFile);

Intent pdfIntent = new Intent(Intent.ACTION_VIEW);

pdfIntent.setDataAndType(path, "application/pdf");

pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

try

{

startActivity(pdfIntent);

}

catch(ActivityNotFoundException e)

{

Toast.makeText(MyPDFDemo.this, "No Application available to view pdf", Toast.LENGTH_LONG).show();

}

}

}

});

}

当我运行这个代码:我曾经看到“没有应用程序可以查看pdf”。任何人都可以请我查看pdf文件。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值