我已成功通过下载管理器从服务器下载文件,但是如果下载完成后我想显示一条消息,我该怎么办?
DownloadManager.Request request = new DownloadManager.Request(Download_Uri);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
request.setAllowedOverRoaming(false);
request.setTitle("Franklyn Downloading " + "Sample" + ".mp3");
request.setDescription("Downloading " + "Sample" + ".mp3");
request.setVisibleInDownloadsUi(true);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "/.Android/" +"/.Obs/"+"/.Android/"+"/.Android/"+"/.Android/"+"/.Android/"+ "/" + "Sample" + ".mp3");
refid = downloadManager.enqueue(request);
Log.e("OUT", "" + refid);
list.add(refid);
答案 0 :(得分:0)
下载完成后,下载管理器发送的广播意向动作“ ACTION_DOWNLOAD_COMPLETE”。因此,您需要注册此接收器。
BroadcastReceiver downloadComplete = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
// show alert
}
};
registerReceiver(downloadComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
答案 1 :(得分:0)
Android DownloadManager在下载完成后发送let parsedData = try FirebaseDecoder().decode(FinDataSample.self, from: value)
parsedData.data.forEach { sample in
print(sample.k1)
print(sample.k2)
print(sample.k3)
print(sample.k4)
sample.val.forEach({ value in
print(value)
})
}
广播意图。
ACTION_DOWNLOAD_COMPLETE
因此,您需要使用广播接收器referenceId检查您的refId。如果两者都匹配,则需要显示警报对话框。