close
Android要檢查上架的App是否有更新版本
一般有兩種做法
一種是去呼叫自己的後台API來判斷
另一種就是去解析Google play的頁面
Github上有一些好用的Library可以來使用看看
有些已經失效了, 以下就介紹一個很好的解決方式
1. 官網https://github.com/RX1226/AppUpdater
2. 在專案的gradle內加入
maven { url 'https://jitpack.io' }
3. 在module的gradle內加入
implementation 'com.github.RX1226:AppUpdater:1.0.0'
4. 然後再要使用的地方呼叫
AppUpdater.getLatestAppVersion(this, new AppUpdater.OnFinishListener() {
@Override
public void onSuccess(Update update) {
Logger.d("getLatestVersion " + update.getLatestVersion());
Logger.d("getReleaseNotes " + update.getReleaseNotes());
Logger.d("getUrlToDownload " + update.getUrlToDownload());
}
@Override
public void onFailed(String errorMessage) {
}
});
他是一個在work thread的callback
這邊會取得Update的資訊
再用版本號來判斷要不要更新就可以了
文章標籤
全站熱搜