How to create alerts if there is an updated version in the app play store android studio
- Buka android studio kemudian coba membuat satu class untuk bisa membuat atau cek update
- Tambahkah perintah berikut pada gradle :
compile 'org.jsoup:jsoup:1.8.3'3. Kemudian Synchronize gradle
4. Tambahkan baris code berikut pada class anda :
private class GetVersionCode extends AsyncTask<Void, String, String> {
@Override protected String doInBackground(Void... voids) {
String newVersion = null;
try {
newVersion = Jsoup.connect("https://play.google.com/store/apps/details?id=" + ScannerID.this.getPackageName() + "&hl=it")
.timeout(30000)
.userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
.referrer("http://www.google.com")
.get()
.select("div[itemprop=softwareVersion]")
.first()
.ownText();
return newVersion;
} catch (Exception e) {
return newVersion;
}
}
@Override protected void onPostExecute(String onlineVersion) {
super.onPostExecute(onlineVersion);
if (onlineVersion != null && !onlineVersion.isEmpty()) {
if (Float.valueOf(currentVersion) < Float.valueOf(onlineVersion)) {
System.out.println("HARUS UPDATE");
//isi dengan perintah anda
}else {
System.out.println("PALING TERBARU");
}
}
Log.d("update", "Current version " + currentVersion + "playstore version " + onlineVersion);
}
}
5. Kemudian tambahkan code berikut untuk menampilkan version code project anda :
PackageManager manager = this.getPackageManager();
try {
PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
String packageName = info.packageName;
int versionCode = info.versionCode;
currentVersion = info.versionName;
} catch (PackageManager.NameNotFoundException e) {
// TODO Auto-generated catch block}
6. Kemudian berikan perintah ini, untuk mengeksekusi :
new GetVersionCode().execute();7. Berikut Contohnya :
0 Komentar
Silahkan Dikomentar ya?