android – 从SD卡读取pdf文件

android – 从SD卡读取pdf文件,第1张

概述我想阅读存储在我的SD卡中的pdf文件,我尝试使用这个片段 File file = new File(Environment.getExternalStorageDirectory() + "/vvveksperten" + "/ypc.pdf"); PackageManager packageManager = getPackageManager(); 我想阅读存储在我的SD卡中的pdf文件,我尝试使用这个片段

file file = new file(Environment.getExternalStorageDirectory()            + "/vvveksperten" + "/ypc.pdf");    PackageManager packageManager = getPackageManager();    Intent testIntent = new Intent(Intent.ACTION_VIEW);    testIntent.setType("application/pdf");    List List = packageManager.queryIntentActivitIEs(testIntent,PackageManager.MATCH_DEFAulT_ONLY);    Intent intent = new Intent();    intent.setAction(Intent.ACTION_VIEW);    Uri uri = Uri.fromfile(file);    intent.setDataAndType(uri,"application/pdf");    startActivity(intent);

但它给了我一个错误.

ERROR/AndroIDRuntime(2611): androID.content.ActivityNotFoundException: No Activity found to handle Intent { act=androID.intent.action.VIEW dat=file:///mnt/sdcard/vvveksperten/ypc.pdf typ=application/pdf }
解决方法 请检查您的设备是否有任何pdf阅读器应用程序,我认为不是..

只需使用此代码,

private voID vIEwpdf(Uri file) {        Intent intent;        intent = new Intent(Intent.ACTION_VIEW);        intent.setDataAndType(file,"application/pdf");        try {            startActivity(intent);        } catch (ActivityNotFoundException e) {            // No application to vIEw,ask to download one            AlertDialog.Builder builder = new AlertDialog.Builder(this);            builder.setTitle("No Application Found");            builder.setMessage("Download one from AndroID Market?");            builder.setPositivebutton("Yes,Please",new DialogInterface.OnClickListener() {                        @OverrIDe                        public voID onClick(DialogInterface dialog,int which) {                            Intent marketIntent = new Intent(Intent.ACTION_VIEW);                            marketIntent                                    .setData(Uri                                            .parse("market://details?ID=com.adobe.reader"));                            startActivity(marketIntent);                        }                    });            builder.setNegativebutton("No,Thanks",null);            builder.create().show();        }    }

如果任何pdf阅读器应用程序不可用,那么此代码是从AndroID市场下载pdf阅读器,但请确保您的设备已预安装AndroID市场应用程序.所以我认为在AndroID设备上尝试这个,而不是模拟器.

总结

以上是内存溢出为你收集整理的android – 从SD卡读取pdf文件全部内容,希望文章能够帮你解决android – 从SD卡读取pdf文件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1123078.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存