安卓APP升级代码
来源:互联网 发布:网络诈骗到哪里报案 编辑:程序博客网 时间:2024/04/30 22:11
20160106日补充如何下载完成后自动弹出安卓界面
思路:接收下载完成的广播,根据下载任务的ID获取APK的安装路径弹出安装界面
<receiver android:name=".receiver.DownLoadCompleteReceiver" >
<intent-filter>
<action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
</intent-filter>
</receiver>
public class DownLoadCompleteReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
long id = PreferencesUtil.getDownLoadId();
if (id == 0l) {
return;
}
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(id);
String saveFileName = null;
Cursor cursor = FileUtils.getDownloadManager(context).query(query);
if (cursor.moveToFirst()) {
saveFileName = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
}
cursor.close();
PreferencesUtil.clearDownLoadId();
/** 下载完成后自动安装apk */
if (saveFileName != null) {
Intent intent1 = new Intent(Intent.ACTION_VIEW);
intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent1.setDataAndType(Uri.parse(saveFileName), "application/vnd.android.package-archive");
context.startActivity(intent1);
}
}
}
}
APP升级代码
import android.app.Activity;import android.app.AlertDialog;import android.app.DownloadManager;import android.content.DialogInterface;import android.content.Intent;import android.net.Uri;import android.os.Environment;public class CheckUpdateUtil implements UICallback { Activity mActivity; /** * 检查更新 */ public void checkUpdate(Activity activity) { mActivity = activity; NetWork.getInstance(activity).reqLoginVolley(activity, UrlUtil.URL_VERSION_INFO, VersionInfo.class, this, null); } @Override public void netBack(Object ob) { try { final VersionInfo versionInfo = (VersionInfo)ob; if (VersionUtil.getVersionCode(mActivity) < versionInfo.getVersionCode()) { AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setTitle("检查更新"); builder.setMessage(String.format("检测到新版(v%s),立即更新\\n%s", versionInfo.getVersionName(),versionInfo.getDes())); if (versionInfo.getIsForce() == 1) { builder.setCancelable(false); } else { builder.setNegativeButton("稍后再说", null); } builder.setPositiveButton("立即更新", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int which) { dialog.dismiss(); DownloadManager.Request request = new DownloadManager.Request(Uri.parse(versionInfo.getLink())); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); request.setTitle("***); request.setAllowedOverRoaming(false); //设置文件存放目录 try { request.setDestinationInExternalFilesDir(mActivity, Environment.DIRECTORY_DOWNLOADS, "kidswant.apk"); long id = FileUtils.getDownloadManager(mActivity).enqueue(request); PreferencesUtil.setDownLoadId(id); } catch (Exception e) {可能因为没有外部存储卡或者DownLoadManager被禁用,上面的报异常,所以使用浏览器访问,为了避免个别浏览器检查长网址安全限制下载文件的原因,这里后台传过来的地址是新浪t.cn短网址在线生成地址:http://dwz.aidmin.cn/,有利于微博里面写,避免长度限制 Uri uri = Uri.parse(versionInfo.getLink()); Intent intent = new Intent(Intent.ACTION_VIEW, uri); mActivity.startActivity(intent); } } }); builder.show(); } else { } }catch (Exception e){ e.printStackTrace(); } }}
- 安卓APP升级代码
- 安卓app升级之安卓app签名
- 从APP升级更新浅谈安卓Service知识
- android代码实现app升级
- 安卓App常见的代码架构分析
- 安卓代码动态切换APP启动图标
- 安卓生成、显示二维码APP代码实现
- 安卓开发debug-app卸载不干净,导致安装、升级不成功问题的解决办法
- 安卓开发实战之app之版本更新升级(DownloadManager和http下载)完整实现
- 安卓7.0手机上遇到的app升级问题终极解决方案
- 安卓开发debug-app卸载不干净,导致安装、升级不成功问题的解决办法
- 安卓 app 本地升级下载后自动安装(小米手机安装包解析失败问题)
- 安卓app上传
- 安卓app优化
- 安卓app运行机制:
- 安卓app设计规范
- 安卓app角标
- 安卓启动APP
- MYSQL乐观锁
- HTML5+CSS3学习(三)头部和元数据
- SPOJ NUMTRYE (gcd)
- 苹果私有api------SpringBoard
- Windows常用快捷键
- 安卓APP升级代码
- WKWebView新特性及JS交互
- c语言学习第三课:条件分支结构
- MySQL最大连接数设置
- QtQuick手机滑动界面Demo
- hadoop-1
- 双指数边缘平滑滤波器用于磨皮算法的尝试
- 使用 xtrabackup做mysql5.6.10主从
- stm32f4 ADC DMA 模式 中断进不去解决