如何下载Adobe Reader编程,如果不存在不存在、如何下载、Adobe、Reader

2023-09-13 00:31:22 作者:Gèt りOut

现在我工作的应用程序。通过我的应用程序的用户可以阅读PDF文件,如果PDF阅读器是不是有那么我的应用程序将自动从网站上进行安装。 这是code我用来读取PDF文件。

 文件文件=新的文件(/ SD卡/ sample.pdf);
PackageManager packageManager = getPackageManager();
意图testIntent =新的意图(Intent.ACTION_VIEW);
testIntent.setType(应用程序/ PDF格式);
列表列表= packageManager.queryIntentActivities(testIntent,PackageManager.MATCH_DEFAULT_ONLY);
如果(则为list.size()大于0&安培;&安培; file.isFile()){
    意向意图=新的意图();
    intent.setAction(Intent.ACTION_VIEW);
    开放的我们的uri = Uri.fromFile(文件);
    intent.setDataAndType(URI,应用程序/ PDF格式);
    startActivity(意向);
}
 

我的疑惑是:

如何检查有一个安装Adobe Reader的电话或不? 如何以编程方式在手机上安装了Adobe Reader? 解决方案

从你的code一些并发症。

Adobe周二正式发布Acrobat Reader 8.0

使用这种code,

 意向意图;
        意图=新的意图(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()显示()。
        }
    }
 

Now I am working on an application. Through my app users can read pdf files and if pdf reader is not there then my app automatically will install it from the site. This is the code I used for reading pdf file.

File file = new File("/sdcard/sample.pdf");
PackageManager packageManager = getPackageManager();
Intent testIntent = new Intent(Intent.ACTION_VIEW);
testIntent.setType("application/pdf");
List list = packageManager.queryIntentActivities(testIntent, PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() > 0 && file.isFile()) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    Uri uri = Uri.fromFile(file);
    intent.setDataAndType(uri, "application/pdf");
    startActivity(intent);
}

My doubts are:

How to check there is a adobe reader installed in phone or not? How to programatically install the adobe reader on a phone?

解决方案

From your code some complication..

Use this code,

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();
        }
    }