Last active
July 21, 2016 16:18
-
-
Save sembozdemir/01de71d88564ddfe4d58f18dab8c038b to your computer and use it in GitHub Desktop.
SampleForceUpdate main activity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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