简体   繁体   English

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

[英]install an apk file programmatically after downloading(android studio)

i know this question has already been asked, but none of them solves my problem. 我知道已经问过这个问题,但是没有一个能解决我的问题。 I want to install an apk (non market app) file which i have downloaded. 我想安装一个我下载的apk(非市场应用程序)文件。

heres my code: 这是我的代码:

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

but when executing this code the package installer is not launching. 但是执行此代码时,软件包安装程序不会启动。 Instead i am getting an open with popup. 相反,我正在使用弹出窗口。 Here's The Screenshot 这是截图

Error is you made the Intent of "install" and using setDataAndType on "intent". 错误是您将Intent设置为“安装”,并且对intent使用了setDataAndType。

Correct code will be:- 正确的代码将是:-

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM