![](/img/trans.png)
[英]java.lang.RuntimeException: Error receiving broadcast Intent
[英]java.lang.RuntimeException: Error receiving broadcast Intent On install Apk
我有一個使用 downloadManager 更新我的應用程序的靜態函數:
public static void downloadApk(final Context context, String apkurl){
String destination = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/";
String fileName = "apk_update.apk";
destination += fileName;
final Uri uri = Uri.parse("file://" + destination);
//Delete update file if exists
File file = new File(destination);
if (file.exists())
file.delete();
//set download manager
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(apkurl));
request.setDescription("...");
request.setTitle("...");
//set destination
request.setDestinationUri(uri);
// get download service and enqueue file
final DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
final long downloadId = manager.enqueue(request);
//set BroadcastReceiver to install app when .apk is downloaded
BroadcastReceiver onComplete = new BroadcastReceiver() {
public void onReceive(Context ctxt, Intent intent) {
Intent installIntent = new Intent(Intent.ACTION_VIEW);
installIntent.setDataAndType(uri, manager.getMimeTypeForDownloadedFile(downloadId));
installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctxt.startActivity(installIntent); ////Error on here
ctxt.unregisterReceiver(this);
// ctxt.finish();
}
};
//register receiver for when .apk download is compete
context.registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}
}
在線下載完成后出現錯誤:
ctxt.startActivity(installIntent);
我的錯誤描述:
java.lang.RuntimeException:接收廣播 Intent 時出錯 { act=android.intent.action.DOWNLOAD_COMPLETE flg=0x10 pkg=...
堆棧跟蹤:堆棧跟蹤
manager.getMimeTypeForDownloadedFile(downloadId)
這將返回application/mobile
作為 MIME 類型。 這不是有效的 MIME 類型。 據推測, DownloadManager
是從您下載此內容的 Web 服務器獲得的。 如果那是您的 Web 服務器,請修復它以對您的內容使用正確的 MIME 類型。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.