问题:
在android4.1系统上打开本地的PDF文件报错:android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW cat=[android.intent.category.DEFAULT] dat=file:///storage/sdcard0/DCIM/Camera/00746145.pdf typ=application/pdf flg=0x10000000 }
原因:
手机上没有支持打开PDF文件的应用
解决办法:
用try、catch处理异常当手机没有可用的应用时提示用户。
Intent intent = new Intent("android.intent.action.VIEW"); intent.addCategory("android.intent.category.DEFAULT"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Uri uri = Uri.fromFile(new File(path)); intent.setDataAndType(uri, "application/pdf");
try { startActivity(intent); } catch (ActivityNotFoundException e) { MyToast.showToast_w(instance, "没有支持PDF文件打开的应用"); }
转载请注明原文地址: https://ju.6miu.com/read-1203875.html