GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |
GeezerVison is showing github.com — 解决使用默认的UpdateDialogFragment在初次安装应用时候,因为DownloadService没有能使用activity.s… by Jiiiiiin · Pull Request #66 · WVector/AppUpdate Conversation
Contributor
解决使用默认的UpdateDialogFragment在初 次安装应用时候,因为DownloadService没有能使用activity.startActivityForResult启动安装界面,导致用户如果取消安装,插件使用者得不到通知的问题: private void startDownload(UpdateAppBean updateApp, final DownloadCallback callback) { mDismissNotificationProgress = updateApp.isDismissNotificationProgress(); String apkUrl = updateApp.getApkFileUrl(); if (TextUtils.isEmpty(apkUrl)) { String contentText = "新版本下载路径错误"; stop(contentText); return; } String appName = AppUpdateUtils.getApkName(updateApp); File appDir = new File(updateApp.getTargetPath()); if (!appDir.exists()) { appDir.mkdirs(); } String target = appDir + File.separator + updateApp.getNewVersion(); updateApp.getHttpManager().download(apkUrl, target, appName, new FileDownloadCallBack(callback)); } private void stop(String contentText) { if (mBuilder != null) { mBuilder.setContentTitle(AppUpdateUtils.getAppName(DownloadService.this)).setContentText(contentText); Notification notification = mBuilder.build(); notification.flags = Notification.FLAG_AUTO_CANCEL; mNotificationManager.notify(NOTIFY_ID, notification); } close(); } private void close() { stopSelf(); isRunning = false; } /** * 进度条回调接口 */ public interface DownloadCallback { // 新增下面的回调口子 /** * 当应用处于前台,准备执行安装程序时候的回调, * * @param file * @return */ boolean onInstallAppAndAppOnForeground(File file); } 在初次应用下载完毕: @Override public void onResponse(File file) { if (mCallBack != null) { if (!mCallBack.onFinish(file)) { close(); return; } } try { if (AppUpdateUtils.isAppOnForeground(DownloadService.this) || mBuilder == null) { //App前台运行 mNotificationManager.cancel(NOTIFY_ID); **// 给应用开发者相应的权限去控制,是否自己处理** boolean temp = mCallBack.onInstallAppAndAppOnForeground(file); if (!temp) { AppUpdateUtils.installApp(DownloadService.this, file); } 比如,在默认的 /** * 回调监听下载 */ private void startDownloadApp(DownloadService.DownloadBinder binder) { // 开始下载,监听下载进度,可以用对话框显示 if (mUpdateApp != null) { binder.start(mUpdateApp, new DownloadService.DownloadCallback() { //.... **@Override public boolean onInstallAppAndAppOnForeground(File file) { // 如果应用处于前台,那么就自行处理应用安装 AppUpdateUtils.installApp(UpdateDialogFragment.this.getActivity(), file); dismiss(); return true; }** }); } } 这样插件使用者就能得到用户取消安装应用的通知: @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (resultCode) { case Activity.RESULT_OK: break; **case Activity.DEFAULT_KEYS_DIALER: switch (requestCode){ // 得到通过UpdateDialogFragment默认dialog方式安装,用户取消安装的回调通知,以便用户自己去判断,比如这个更新如果是强制的,但是用户下载之后取消了,在这里发起相应的操作 case AppUpdateUtils.REQ_CODE_INSTALL_APP: Toast.makeText(this,"用户取消了安装包的更新", Toast.LENGTH_LONG).show(); break; } break;** case Activity.RESULT_CANCELED: break; default: } }
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions…tartActivityForResult启动安装界面,导致用户如果取消安装,插件使用者得不到通知的问题
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersNo reviewsUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later. | |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |