Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Whats New Dialog with Follow on Twitter Button
private void whatsNewDialog() {
//Dialog dialog = new Dialog(main.this);
final Dialog dialog = new Dialog(this,;
//dialog.setTitle(getString(R.string.app_name) + " v" + currentAppVersion);
//set up Title
TextView textWhatsNewTitle = (TextView) dialog.findViewById(;
textWhatsNewTitle.setText(getString(R.string.mainTitle) + " v" + currentAppVersion);
//set up text content
TextView textWhatsNewContent = (TextView) dialog.findViewById(;
//set up image view
ImageView img = (ImageView) dialog.findViewById(;
//set up Okay button
Button btnOkay = (Button) dialog.findViewById(;
btnOkay.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
editor.putLong(PREF_WHATS_NEW_LAST_VERSION, currentAppVersionCode);
//check for Twitter application
boolean twitterInstalled = false;;
try {
PackageManager packman = getPackageManager();
packman.getPackageInfo("", 0);
twitterInstalled = true;
} catch (Exception ex) {
twitterInstalled = false;
//set up Twitter button
Button btnFollow = (Button) dialog.findViewById(;
btnFollow.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// this is the intent you actually want.
// grabbed this by hooking a debugger up to twitter and debugging into android framework source.
// this let me inspect the contents of the intent.
Intent i = new Intent();
i.setClassName("", "");
i.putExtra("screen_name", "joeykrim");
try {
catch (Exception ex) {
// uh something failed
//Log.d(LOG_TAG, "twiterinstalled: " + twitterInstalled);
if (twitterInstalled) btnFollow.setVisibility(VISIBILITY_VISIBLE);
//now that the dialog is set up, it's time to show it;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment