我想在pdf viewer中从URL打开pdf
我尝试下面的代码。它是开放的pdf查看器,但最近的文档没有我的URL?
如何直接在pdfviewer中打开文件?
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://inventwithpython.com/hackingciphers.pdf"));
intent.setType("application/pdf");
PackageManager pm = getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
if (activities.size() > 0) {
startActivity(intent);
} else {
// Do something else here. Maybe pop up a Dialog or Toast
Toast.makeText(getApplicationContext(),"No pdf found" , Toast.LENGTH_LONG).show();
final String appName = "com.adobe.reader";
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+appName)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id="+appName)));
}
}
答案 0 :(得分:0)
试试此代码
Uri uri = Uri.parse("http://inventwithpython.com/hackingciphers.pdf");
Intent pdfOpenintent = new Intent(Intent.ACTION_VIEW,uri);
pdfOpenintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
pdfOpenintent.setDataAndType(uri, "application/pdf"); // )
try {
startActivity(pdfOpenintent);
} catch (ActivityNotFoundException e) {
}