如何下载Adobe Reader编程,如果不存在 [英] how to download adobe reader programatically if not exists

查看:159
本文介绍了如何下载Adobe Reader编程,如果不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我工作的应用程序。通过我的应用程序的用户可以阅读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(意向);
}
 

我的疑惑是:

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

从你的code一些并发症。

使用这种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:

  1. How to check there is a adobe reader installed in phone or not?
  2. 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();
        }
    }

这篇关于如何下载Adobe Reader编程,如果不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆