您的位置:首页 > 移动开发 > Android开发

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)
{
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息