Nav*_*inC 8 pdf android adobe-reader
我正在编写一个Android应用程序来在设备上显示pdf文件.我需要使用Adobe Reader的当前版本代码(35498)来显示pdf文件.我有代码来显示屏幕上的文件列表.现在我需要调用每个文档的Adobe Reader(而不是设备上安装的任何其他pdf阅读器).我不确定我是如何编码的.我是一个Android新手.任何帮助将不胜感激.
感谢提前,纳文
Mud*_*sir 10
请尝试以下代码
private void loadDocInReader(String doc)
throws ActivityNotFoundException, Exception {
try {
Intent intent = new Intent();
intent.setPackage("com.adobe.reader");
intent.setDataAndType(Uri.parse(doc), "application/pdf");
startActivity(intent);
} catch (ActivityNotFoundException activityNotFoundException) {
activityNotFoundException.printStackTrace();
throw activityNotFoundException;
} catch (Exception otherException) {
otherException.printStackTrace();
throw otherException;
}
}
Run Code Online (Sandbox Code Playgroud)
Jak*_*ile 10
我看到你想要专门打开Adobe,但你可能想要考虑采用类似于Android的方式来打开一般意图并允许用户选择它如何打开.供您参考,您可以使用以下代码执行此操作:
private void openFile(File f, String mimeType)
{
Intent viewIntent = new Intent();
viewIntent.setAction(Intent.ACTION_VIEW);
viewIntent.setDataAndType(Uri.fromFile(file), mimeType);
// using the packagemanager to query is faster than trying startActivity
// and catching the activity not found exception, which causes a stack unwind.
List<ResolveInfo> resolved = getPackageManager().queryIntentActivities(viewIntent, 0);
if(resolved != null && resolved.size() > 0)
{
startActivity(viewIntent);
}
else
{
// notify the user they can't open it.
}
}
Run Code Online (Sandbox Code Playgroud)
如果您确实需要专门使用Abode Reader和特定版本,则需要使用它来查询它 PackageManager.getPackageInfo(String, int)
如果您处于"在线模式",这是一个使用Google文档的有趣替代解决方案.
String myPDFURL = "http://{link of your pdf file}";
String link;
try {
link = "http://docs.google.com/viewer?url="
+ URLEncoder.encode(myPDFURL, "UTF-8")
+ "&embedded=true";
} catch (Exception e) {
e.printStackTrace();
}
Uri uri = Uri.parse(link);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10795 次 |
最近记录: |