Added version code check.
This commit is contained in:
parent
2a18eacf62
commit
e7abeb5ad9
|
@ -209,21 +209,25 @@ 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.
|
||||||
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
|
if (!BuildConfig.FLAVOR.equals(getString(R.string.app_flavor_github))) {
|
||||||
= new NotificationChannel(appUpdateId, appUpdateName, importance);
|
|
||||||
appUpdateChannel.setDescription(appUpdateDescription);
|
|
||||||
|
|
||||||
NotificationManager appUpdateNotificationManager
|
final String appUpdateId
|
||||||
= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
= getString(R.string.app_update_notification_channel_id);
|
||||||
appUpdateNotificationManager.createNotificationChannel(appUpdateChannel);
|
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
|
@Nullable
|
||||||
|
|
|
@ -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));
|
||||||
|
|
Loading…
Reference in New Issue