Android(安卓)APP 版本更新通知代码
16lz
2021-12-04
public class UpdateNotification{ private static HashMap 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) { } }}
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer