Android自动更新组件包——支持英语国际化

开发中,软件的发布更新功能是必不可少的,原来此功能是自己编写的,在一个项目中使用还挺方便,但随着项目的增多,每次需要使用到下载更新功能的时候就又得从原先的项目中去把各种资源整理过来,特别耗时,并且使得项目中的文件资源略多,不利于后期维护。后来在github上去找了一个人家写好的开元工具包,但是在使用中发现有写bug,但总体功能还好,无赖只好咨自寻修改。这里讲组件及使用方式分享出来,供大家参考。

package com.example.mytest;

import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
import com.lurencun.service.autoupdate.AppUpdate;
import com.lurencun.service.autoupdate.AppUpdateService;
import com.lurencun.service.autoupdate.ResponseParser;
import com.lurencun.service.autoupdate.Version;

public class TestActivity extends Activity {

	// 监测是否更新
	private AppUpdate appUpdate;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		try {
			String UPDATE_URL = "http://home.iusung.com/android/NewMIStxt.txt";
			appUpdate = AppUpdateService.getAppUpdate(getApplicationContext());
			appUpdate.setCheckUrl(UPDATE_URL);
			appUpdate.setIsShowLastVersion(true);
			appUpdate.setResponseParser(new ResponseParser() {
				@Override
				public Version parser(String response) {
					// TODO Auto-generated method stub
					Version version = null;
					try {
						JSONObject versionObject = new JSONObject(response);
						int versionCode = versionObject.getInt("versionCode");
						String versionName = versionObject
								.getString("versionName");
						String appName = versionObject.getString("releaseApp");
						String appName_en = versionObject
								.getString("releaseApp_en");
						String appDescribe = versionObject
								.getString("releaseNote");
						String appDescribe_en = versionObject
								.getString("releaseNote_en");
						String appUrl = versionObject.getString("releaseUrl");
						String releaseTime = versionObject
								.getString("releaseTime");
						version = new Version(versionCode, versionName,
								appName, appName_en, appDescribe,
								appDescribe_en, appUrl, releaseTime);
					} catch (JSONException e) {
						e.printStackTrace();
					}
					return version;
				}
			});
			appUpdate.checkAndShow();
			appUpdate.callOnResume();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			Toast.makeText(getApplicationContext(), "检测更新错误,请与管理员联系",
					Toast.LENGTH_SHORT).show();
		}
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值