阅读从SD卡的PDF文件 [英] Read pdf file from sd card
本文介绍了阅读从SD卡的PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想读取存储在我的sd卡的PDF文件,我试图用这个片段
档案文件=新的文件(Environment.getExternalStorageDirectory()
+/ vvveksperten+/ypc.pdf);
PackageManager packageManager = getPackageManager();
意图testIntent =新的意图(Intent.ACTION_VIEW);
testIntent.setType(应用程序/ PDF格式);
列表列表= packageManager.queryIntentActivities(testIntent,
PackageManager.MATCH_DEFAULT_ONLY);
意向意图=新的意图();
intent.setAction(Intent.ACTION_VIEW);
开放的我们的uri = Uri.fromFile(文件);
intent.setDataAndType(URI,应用程序/ PDF格式);
startActivity(意向);
但它给了我一个错误。
ERROR / AndroidRuntime(2611):android.content.ActivityNotFoundException:无活动处理意向{行为= android.intent.action.VIEW DAT =文件:/// MNT / SD卡/ vvveksperten / ypc.pdf典型值=应用程序/ PDF}
解决方案
请检查您的设备可在任何PDF阅读器应用程序,我想没有任何..
只要使用这个code,
私人无效viewPdf(URI文件){
意向意图;
意图=新的意图(Intent.ACTION_VIEW);
intent.setDataAndType(文件,应用程序/ PDF格式);
尝试 {
startActivity(意向);
}赶上(ActivityNotFoundException E){
//没有应用程序来查看,请下载一个
AlertDialog.Builder建设者=新AlertDialog.Builder(本);
builder.setTitle(无应用程序找到);
builder.setMessage(从Android Market下载一个?);
builder.setPositiveButton(是的,请,
新DialogInterface.OnClickListener(){
@覆盖
公共无效的onClick(DialogInterface对话,诠释它){
意图marketIntent =新的意图(Intent.ACTION_VIEW);
marketIntent
.setData(URI
.parse(市场://细节ID = com.adobe.reader));
startActivity(marketIntent);
}
});
builder.setNegativeButton(不,谢谢,NULL);
builder.create()显示()。
}
}
如果任何不可用PDF阅读器应用程序,然后这个code是从Android Market下载PDF文档阅读器,但可以肯定你的设备有pre安装 Android的市场应用程序。所以我觉得这个尝试在Android设备上,而不是模拟器。
I want to read a pdf file stored in my sd card, I tried using this snippet
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);
but it gave me an error.
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 }
解决方案
Please check your device is any pdf reader application available, I think isn't any..
Just use this code,
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();
}
}
If any pdf reader application not available then this code is download pdf reader from android market, But be sure your device has pre-installed android-market application. So I think try this on android device, rather then emulator.
这篇关于阅读从SD卡的PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文