系统自带的DownloadManager下载
IntentFilter filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
mReceiver = new Receiver();
registerReceiver(mReceiver, filter);
//系统提供的DownloadManager来下载
private void startDownload() {
final DownloadManager downloadManager = (DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(DOWNLOAD_URL));
request.setDestinationInExternalFilesDir(this, null, "yixin.apk");
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setMimeType("application/vnd.android.package-archive");
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
mDownloadId = downloadManager.enqueue(request);
}
public class Receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent