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,7 +209,10 @@ public class App extends Application {
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.createNotificationChannel(mChannel); mNotificationManager.createNotificationChannel(mChannel);
// Set up notification channel for app update // Set up notification channel for app update only if it's a github apk.
if (!BuildConfig.FLAVOR.equals(getString(R.string.app_flavor_github))) {
final String appUpdateId final String appUpdateId
= getString(R.string.app_update_notification_channel_id); = getString(R.string.app_update_notification_channel_id);
final CharSequence appUpdateName final CharSequence appUpdateName
@ -225,6 +228,7 @@ public class App extends Application {
= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
appUpdateNotificationManager.createNotificationChannel(appUpdateChannel); appUpdateNotificationManager.createNotificationChannel(appUpdateChannel);
} }
}
@Nullable @Nullable
public static RefWatcher getRefWatcher(Context context) { public static RefWatcher getRefWatcher(Context context) {

View File

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