Android – Added Follow Developer on Twitter Button


There is a great piece of java code posted by koush on Github’s gist showing how to interface with the official Android Twitter application. The key was not only knowing the package name, but knowing the right extra information to add to the intent sent to the Twitter application.
The below code and two links below illustrate a simple method of firing off an intent loaded with the proper profile activity class name and screen name to pull up the user’s page in the official Twitter application. The second link shows how I added this to a custom Whats New dialog used in my applications.


koush gist on github:
my gist on github with whats new dialog function:

Copy of my gist on github

    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;

Leave a Reply

Your email address will not be published. Required fields are marked *