auto-update-service
An Android Service, provide a easy way to update app automatically.
Android App自動更新服務。
說明
AppUpdate為Android App自動升級功能提供兩個便捷的接口:
- 1: checkLatestVersion(String updateUrl,ResponseParser parser);
檢測指定URL的版本信息,如果版本信息高於當前應用的版本號,則彈出版本信息窗口,提示用戶升級。
彈出窗口可以通過setCustomDisplayer(Displayer d)設置自定義顯示窗口。
- 2: checkAndInstallDirectly(String updateUrl,ResponseParser parser);
檢測指定URL的版本信息,如果版本信息高於當前應用版本號,則直接下載並安裝。
響應解析 (ResponseParser)
ResponseParser解析接口。指定URL返回的響應數據,需要通過此接口解析成Version對象。
**所以,你需要實現此接口**
簡單的使用例子
public class MainActivity extends Activity {
AppUpdate appUpdate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
appUpdate = AppUpdateService.getAppUpdate(this);
View check = findViewById(R.id.check);
check.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 檢查最新版本,並彈出窗口
appUpdate.checkLatestVersion("http://api.ilovedeals.sg/app_release/latest?app_type=android-mobile",
new SimpleJSONParser());
}
});
View download = findViewById(R.id.download);
download.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 檢查最新版本,不彈出提示窗口,直接下載升級
appUpdate.checkAndInstallDirectly("http://api.ilovedeals.sg/app_release/latest?app_type=android-mobile",
new SimpleJSONParser());
}
});
}
@Override
protected void onResume(){
super.onResume();
// ********
appUpdate.callOnResume();
}
@Override
protected void onPause(){
super.onPause();
// ********
appUpdate.callOnPause();
}
}
Copyright and Licensewww.2cto.com
Copyright 2013
[email protected]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.