开发者

Displaying PDF in a view in Android

开发者 https://www.devze.com 2023-02-25 05:50 出处:网络
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 wi

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

精彩评论

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