| | |
| | | |
| | | import androidx.annotation.Nullable; |
| | | |
| | | import android.app.DownloadManager; |
| | | import android.content.BroadcastReceiver; |
| | | import android.content.ClipboardManager; |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.IntentFilter; |
| | | import android.net.Uri; |
| | | import android.os.Bundle; |
| | | import android.os.Environment; |
| | | import android.text.TextUtils; |
| | | import android.view.View; |
| | | import android.widget.Toast; |
| | | |
| | | import com.baidu.idl.main.facesdk.FaceAuth; |
| | | import com.baidu.idl.main.facesdk.callback.Callback; |
| | |
| | | |
| | | getDB().accreditOffBtn.setOnClickListener(this); |
| | | getDB().btnDown.setOnClickListener(this); |
| | | setupDownloadManager(); |
| | | setupDownloadReceiver(); |
| | | } |
| | | |
| | | @Subscribe |
| | |
| | | } |
| | | if(!TextUtils.isEmpty(MApplication.getConfigBean().getActivateFileUrl())){ |
| | | isDownLoad = true; |
| | | FileUtil.downLoadFile(filePath, MApplication.getConfigBean().getActivateFileUrl(), new FileUtil.DownLoadCallBack() { |
| | | @Override |
| | | public void sucess() { |
| | | ToastView.show(MApplication.mContext,"下载成功"); |
| | | isDownLoad = false; |
| | | } |
| | | |
| | | @Override |
| | | public void err(String e) { |
| | | ToastView.show(MApplication.mContext,e); |
| | | isDownLoad = false; |
| | | } |
| | | }); |
| | | startDownload(MApplication.getConfigBean().getActivateFileUrl()); |
| | | } |
| | | break; |
| | | // 离线激活 |
| | |
| | | @Override |
| | | protected void onDestroy() { |
| | | super.onDestroy(); |
| | | if (downloadReceiver != null) { |
| | | unregisterReceiver(downloadReceiver); |
| | | } |
| | | } |
| | | |
| | | private BroadcastReceiver downloadReceiver; |
| | | private DownloadManager downloadManager; |
| | | private long downloadId; |
| | | |
| | | private void setupDownloadManager() { |
| | | downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); |
| | | } |
| | | |
| | | |
| | | private void startDownload(String url) { |
| | | try { |
| | | DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); |
| | | |
| | | // 设置下载参数 |
| | | request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE); |
| | | request.setTitle("文件下载"); |
| | | request.setDescription("正在下载文件..."); |
| | | request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); |
| | | request.setDestinationInExternalPublicDir("", "License.zip"); |
| | | |
| | | // 开始下载 |
| | | downloadId = downloadManager.enqueue(request); |
| | | Toast.makeText(mContext, "下载已开始", Toast.LENGTH_SHORT).show(); |
| | | |
| | | } catch (Exception e) { |
| | | isDownLoad = false; |
| | | Toast.makeText(this, "下载失败: " + e.getMessage(), Toast.LENGTH_LONG).show(); |
| | | } |
| | | } |
| | | |
| | | private void setupDownloadReceiver() { |
| | | downloadReceiver = new BroadcastReceiver() { |
| | | @Override |
| | | public void onReceive (Context context, Intent intent){ |
| | | long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1); |
| | | if (id == downloadId) { |
| | | isDownLoad = false; |
| | | Toast.makeText(context, "文件下载完成", Toast.LENGTH_LONG).show(); |
| | | } |
| | | } |
| | | }; |
| | | registerReceiver(downloadReceiver,new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); |
| | | } |
| | | } |