Android APP 版本更新通知代码
2012-09-12 10:38
501 查看
public class UpdateNotification { private static HashMap<String, String> getLatestVersionData(String paramString) { HashMap localHashMap = new HashMap(); String str = "http://xxxxx/service_check_version.do?appCode=" + paramString; DefaultHttpClient localDefaultHttpClient = new DefaultHttpClient(); try { HttpResponse localHttpResponse = localDefaultHttpClient.execute(new HttpGet(str)); if (localHttpResponse.getStatusLine().getStatusCode() == 200) { ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream(); localHttpResponse.getEntity().writeTo(localByteArrayOutputStream); localByteArrayOutputStream.close(); JSONObject localJSONObject = new JSONObject(localByteArrayOutputStream.toString()); localHashMap.put("versionCode", localJSONObject.getString("versionCode")); localHashMap.put("versionManageOption", localJSONObject.getString("versionManageOption")); } return localHashMap; } catch (ClientProtocolException localClientProtocolException) { Log.i("SERVER_ACCESS_ERROR", localClientProtocolException.getMessage()); } catch (IOException localIOException) { Log.i("SERVER_ACCESS_ERROR", localIOException.getMessage()); } catch (JSONException localJSONException) { Log.i("SERVER_ACCESS_ERROR", localJSONException.getMessage()); } } public static void showUpdateDialogIfNecessary(String paramString, Context paramContext) { try { new Thread(new Runnable(paramString, paramContext) { public void run() { HashMap localHashMap = UpdateNotification.access$0(UpdateNotification.this); if ((!localHashMap.containsKey("versionCode")) || (!localHashMap.containsKey("versionManageOption")) || (localHashMap.get("versionCode") == null) || (((String)localHashMap.get("versionCode")).equals(""))) return; try { int i = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionCode; int j = Integer.parseInt((String)localHashMap.get("versionCode")); String str = (String)localHashMap.get("versionManageOption"); if (j <= i) return; if (!str.equals("required")) new AlertDialog.Builder(this).setIcon(R.id.icon).setTitle("New update available!").setPositiveButton("Update Now", new DialogInterface.OnClickListener(this.val$context) { public void onClick(DialogInterface paramDialogInterface, int paramInt) { Intent localIntent = new Intent("android.intent.action.VIEW", Uri.parse("market://details?id=" + this.getPackageName())); .startActivity(localIntent); } }).setNegativeButton("Later", new DialogInterface.OnClickListener() { public void onClick(DialogInterface paramDialogInterface, int paramInt) { } }).show(); else new AlertDialog.Builder(this).setIcon(R.id.icon).setTitle("New update available!").setPositiveButton("Update Now", new DialogInterface.OnClickListener(this.val$context) { public void onClick(DialogInterface paramDialogInterface, int paramInt) { Intent localIntent = new Intent("android.intent.action.VIEW", Uri.parse("market://details?id=" + this.getPackageName())); this.startActivity(localIntent); } }).show(); } catch (PackageManager.NameNotFoundException localNameNotFoundException) { Log.i("VERSION_ACQUISITION_ERROR", localNameNotFoundException.getMessage()); } } }).start(); return; } catch (Exception localException) { } } }
相关文章推荐
- Android App更新版本以及提示用户下载最新apk(有图,有代码,有最终效果图)详细解释及思路
- Android 实现通知栏通知APP版本更新
- Android 如何通知用户更新app的版本
- Android 如何通知用户更新app的版本
- Android学&nbsp;App自动更新之通知栏下…
- android实现通知栏下载更新app示例
- Android应用APP自动更新功能的代码实现
- android APP检测版本更新以及后台服务更新
- Android 轻松实现后台搭建+APP版本更新
- Android App自动更新之通知栏下载
- Android实现App版本自动更新
- Android App 版本更新实现
- [Android]一句话实现APP自动更新(带通知栏)
- Android实现版本更新通知栏下载
- android开发app版本更新(参考别人后改动版)
- Android更新app的版本
- Android App的版本升級(迭代/更新)
- Android使用AsyncHttpClient给APP更新版本并安装
- Android系列学习讲座之二--App自动更新之通知栏下载
- Android app更新版本