Added version code check.

This commit is contained in:
Kartikey Kushwaha 2018-08-17 00:53:42 +05:30
parent 2a18eacf62
commit e7abeb5ad9
2 changed files with 23 additions and 17 deletions

View File

@ -209,21 +209,25 @@ public class App extends Application {
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.createNotificationChannel(mChannel);
// Set up notification channel for app update
final String appUpdateId
= getString(R.string.app_update_notification_channel_id);
final CharSequence appUpdateName
= getString(R.string.app_update_notification_channel_name);
final String appUpdateDescription
= getString(R.string.app_update_notification_channel_description);
// Set up notification channel for app update only if it's a github apk.
NotificationChannel appUpdateChannel
= new NotificationChannel(appUpdateId, appUpdateName, importance);
appUpdateChannel.setDescription(appUpdateDescription);
if (!BuildConfig.FLAVOR.equals(getString(R.string.app_flavor_github))) {
NotificationManager appUpdateNotificationManager
= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
appUpdateNotificationManager.createNotificationChannel(appUpdateChannel);
final String appUpdateId
= getString(R.string.app_update_notification_channel_id);
final CharSequence appUpdateName
= getString(R.string.app_update_notification_channel_name);
final String appUpdateDescription
= getString(R.string.app_update_notification_channel_description);
NotificationChannel appUpdateChannel
= new NotificationChannel(appUpdateId, appUpdateName, importance);
appUpdateChannel.setDescription(appUpdateDescription);
NotificationManager appUpdateNotificationManager
= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
appUpdateNotificationManager.createNotificationChannel(appUpdateChannel);
}
}
@Nullable

View File

@ -112,10 +112,10 @@ public class CheckForNewAppVersionTask extends AsyncTask<Void, Void, String> {
JSONObject githubStableObject = githubObject.getJSONObject("stable");
String versionName = githubStableObject.getString("version");
// String versionCode = githubStableObject.getString("version_code");
String versionCode = githubStableObject.getString("version_code");
String apkLocationUrl = githubStableObject.getString("apk");
compareAppVersionAndShowNotification(versionName, apkLocationUrl);
compareAppVersionAndShowNotification(versionName, apkLocationUrl, versionCode);
} catch (JSONException ex) {
ex.printStackTrace();
@ -129,11 +129,13 @@ public class CheckForNewAppVersionTask extends AsyncTask<Void, Void, String> {
* @param versionName
* @param apkLocationUrl
*/
private void compareAppVersionAndShowNotification(String versionName, String apkLocationUrl) {
private void compareAppVersionAndShowNotification(String versionName,
String apkLocationUrl,
String versionCode) {
int NOTIFICATION_ID = 2000;
if (!BuildConfig.VERSION_NAME.equals(versionName.replace("v", ""))) {
if (BuildConfig.VERSION_CODE < Integer.valueOf(versionCode)) {
// A pending intent to open the apk location url in the browser.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(apkLocationUrl));