| | |
| | | //设置监听Uri.parse("content://downloads/my_downloads") |
| | | weakReference.get().getContentResolver().registerContentObserver(Uri.parse("content://downloads/my_downloads"), true, |
| | | mDownLoadChangeObserver); |
| | | |
| | | IntentFilter intentFilter = new IntentFilter(); |
| | | intentFilter.addAction(DownloadManager.ACTION_DOWNLOAD_COMPLETE); |
| | | // 注册广播,监听APK是否下载完成 |
| | | weakReference.get().registerReceiver(mDownloadReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); |
| | | weakReference.get().registerReceiver(mDownloadReceiver, intentFilter); |
| | | } |
| | | |
| | | /** |
| | |
| | | downSuccess = true; |
| | | Log.i(TAG, "下载进度:完成"); |
| | | } |
| | | Log.i(TAG, "下载进度:" + bytesAndStatus[0] + "/" + bytesAndStatus[1] + ""); |
| | | long value = bytesAndStatus[0] * 100L / bytesAndStatus[1]; |
| | | Log.i(TAG, "下载进度:" + value + ""); |
| | | } |
| | | |
| | | class DownloadChangeObserver extends ContentObserver { |
| | |
| | | |
| | | @Override |
| | | public void permissionFail() { |
| | | HdlThreadLogic.toast(HDLApp.getInstance(), HDLApp.getInstance().getResources().getString(R.string.app_update_fail)); |
| | | HdlThreadLogic.toast(HDLApp.getInstance(), HDLApp.getInstance().getAppLocaleContext().getString(R.string.app_update_fail)); |
| | | } |
| | | }; |
| | | new Handler().postDelayed(new Runnable() { |
| | |
| | | uri = Uri.fromFile(apkFile); |
| | | } else { // Android 7.0 以上 |
| | | uri = FileProvider.getUriForFile(context, |
| | | "com.hdl.debugtreasure.dc.fileprovider", |
| | | "com.hdl.photovoltaic.fileProvider", |
| | | new File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), HdlAppUpdateLogic.getInstance().getApkFileName())); |
| | | intentInstall.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); |
| | | } |