我用DownloadManager庫下載了一個.apk文件,並且我有一個用於下載服務的BroadcastReceiver。這是我在onRecieve(代碼):Android DownloadManager類:getUriForDownloadedFile返回錯誤路徑
long id = intent.getExtras().getLong(DownloadManager.EXTRA_DOWNLOAD_ID);
DownloadManager dm = (DownloadManager)context.getSystemService(context.DOWNLOAD_SERVICE);
intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(dm.getUriForDownloadedFile(id), "application/vnd.android.package-archive");
context.startActivity(intent);
這裏的問題是,當我打電話UriForDownloadedFile(ID)somtimes返回文件:///storage/emulated/0/Download/example.apk 和其它設備上返回 內容://下載/ all_downloads/183
,我不能用(內容://下載/ all_downloads/183)安裝APK路徑
**注意! 'DownloadManager'並不總是下載到我確定的路徑!**什麼時候?當文件已存在於路徑中時。然後'DownloadManager'將它下載到另一個路徑中。 –