Skip to content

Instantly share code, notes, and snippets.

@esabook
Last active February 8, 2020 07:47
Show Gist options
  • Save esabook/bd1b7b980a3ba46745ce03e036d5494d to your computer and use it in GitHub Desktop.
Save esabook/bd1b7b980a3ba46745ce03e036d5494d to your computer and use it in GitHub Desktop.
app center update listener
package ***.utils;
import android.app.Activity;
import android.support.v7.app.AlertDialog;
import com.microsoft.appcenter.distribute.Distribute;
import com.microsoft.appcenter.distribute.DistributeListener;
import com.microsoft.appcenter.distribute.ReleaseDetails;
import com.microsoft.appcenter.distribute.UpdateAction;
import ***.BuildConfig;
import ***.R;
import ***.activity.SplashScreen;
public class __UpdateListener implements DistributeListener {
static boolean isDownloadPosponed = false;
@Override
public boolean onReleaseAvailable(Activity activity, ReleaseDetails releaseDetails) {
if (isDownloadPosponed) return true;
if (__GlobalApp.getActivity().getClass().equals(SplashScreen.class)) return true;
// Look at releaseDetails public methods to get version information, release notes text or release notes URL
String versionName = releaseDetails.getShortVersion();
String releaseNotes = releaseDetails.getReleaseNotes();
int versionCode = releaseDetails.getVersion();
if (versionCode <= BuildConfig.VERSION_CODE) return true;
// Build our own dialog title and message
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity);
dialogBuilder.setTitle(String.format("%s %s %s!", activity.getResources().getString(R.string.version), versionName, activity.getResources().getString(R.string.available)));
dialogBuilder.setMessage(releaseNotes);
// Mimic default SDK buttons
dialogBuilder.setPositiveButton(com.microsoft.appcenter.distribute.R.string.appcenter_distribute_update_dialog_download, (dialog, which) -> {
Distribute.notifyUpdateAction(UpdateAction.UPDATE);
});
dialogBuilder.setNegativeButton(R.string.ask_me_tomorrow, (dialog, which) -> {
Distribute.notifyUpdateAction(UpdateAction.POSTPONE);
});
dialogBuilder.setCancelable(true);
dialogBuilder.setOnCancelListener(v -> isDownloadPosponed = true);
dialogBuilder.create().show();
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment