0
首先,寫我的服務器URL 2.下載APK 3.安裝APK
當我安裝APK
解析錯誤消息。 但重試安裝,成功安裝apk。
總之,首先嚐試安裝apk。嘗試後解析錯誤消息 。成功安裝apk。
String url = "https://myserver/.apk ";
File apkFile = new File("/sdcard/Download/openapk.apk");
Uri mUri = Uri.parse(url);
DownloadManager.Request r = new DownloadManager.Request(mUri);
r.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "openapk.apk");
r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
DownloadManager dm = (DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE);
dm.enqueue(r);
Uri apkUri = Uri.fromFile(apkFile);
Intent webIntent =new Intent(Intent.ACTION_VIEW);
webIntent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
webIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(webIntent);
[解析錯誤安裝的APK結果]的可能的複製(http://stackoverflow.com/questions/36783585/installing-an-apk-results-in-a-parse-錯誤) –