开发者

Displaying PDF in a view in Android

In Android I need to display a PDF file, which is in the asset folder, in a view. Can anyone help me out with t开发者_JAVA技巧he sample code?


I don't think its possible to display it in a view. You will have to make an Intent and then call an external program to do so.

File sd = new File("example.pdf");
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromFile(sd));
intent.setDataAndType(Uri.fromFile(sd), "application/pdf");
try {
    getContext().startActivity(intent);
} catch(ActivityNotFoundException e){
    // Show a message that a PDF viewer is not installed
    Toast.makeText("No PDF reader available",Toast.LENGTH_LONG).show();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜