下载后以编程方式安装apk文件(android studio)

时间:2016-07-02 12:33:44

标签: java android

我知道这个问题已被提出,但没有一个能解决我的问题。我想安装一个我已下载的apk(非市场应用)文件。

继承我的代码:

                Intent install = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/Android/data/com.temp.tempaa/files/Download/update.apk")), "application/vnd.android.package-archive");
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(install);

但是在执行此代码时,包安装程序未启动。相反,我正在打开弹出窗口。Here's The Screenshot

1 个答案:

答案 0 :(得分:0)

错误是你做了“安装”的意图并在“意图”上使用了setDataAndType。

正确的代码将是: -

Intent install = new Intent(Intent.ACTION_VIEW);
            install.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/Android/data/com.temp.tempaa/files/Download/update.apk")), "application/vnd.android.package-archive");
            install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(install);
相关问题