Skip to content

Instantly share code, notes, and snippets.

@sembozdemir
Last active July 21, 2016 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sembozdemir/01de71d88564ddfe4d58f18dab8c038b to your computer and use it in GitHub Desktop.
Save sembozdemir/01de71d88564ddfe4d58f18dab8c038b to your computer and use it in GitHub Desktop.
SampleForceUpdate main activity
public class MainActivity extends AppCompatActivity
implements ForceUpdateChecker.OnUpdateNeededListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ForceUpdateChecker.with(this).onUpdateNeeded(this).check();
}
@Override
public void onUpdateNeeded(final String updateUrl) {
AlertDialog dialog = new AlertDialog.Builder(this)
.setTitle("New version available")
.setMessage("Please, update app to new version to continue reposting.")
.setPositiveButton("Update",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
redirectStore(updateUrl);
}
}).setNegativeButton("No, thanks",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
}).create();
dialog.show();
}
private void redirectStore(String updateUrl) {
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(updateUrl));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment