[英]install an apk file programmatically after downloading(android studio)
我知道已經問過這個問題,但是沒有一個能解決我的問題。 我想安裝一個我下載的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);
但是執行此代碼時,軟件包安裝程序不會啟動。 相反,我正在使用彈出窗口。 這是截圖
錯誤是您將Intent設置為“安裝”,並且對intent使用了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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.