Compose Tweets

TweetComposer provides two ways to compose Tweets:

  1. Launch the Twitter application’s Tweet Composer - a feature-rich composer which supports attaching images and videos.
  2. Launch the Twitter Kit Native Composer - a lightweight composer which lets users compose Tweets from within your application.

Launching Twitter Composer

The Twitter Android application allows apps to start the Tweet composer via an Intent. The Twitter Android composer is feature-rich, familiar to users, and has options for attaching images and videos.

Build an Intent

Start construction of a Tweet composer by using the TweetComposer Builder.


TweetComposer.Builder builder = new TweetComposer.Builder(this)
     .text("just setting up my Twitter Kit.")

The image Uri should be a Uri using the content:// scheme. For example,

Uri imageUri = FileProvider.getUriForFile(MainActivity.this,
  BuildConfig.APPLICATION_ID + ".file_provider",
  new File("/path/to/image"));

If the Twitter app is not installed, the intent will launch in a browser, but the specified image will be ignored. For more details on correctly setting up a FileProvider see Setup Sharing.

Twitter Kit Native Composer

The Twitter Kit Native Composer is a lightweight composer which lets users compose Tweets from within your application. It does not depend on the Twitter for Android app being installed.


Intent Builder

After authenticating a user, build an Intent to start the TweetComposer’s ComposerActivity.

final TwitterSession session = TwitterCore.getInstance().getSessionManager()
final Intent intent = new ComposerActivity.Builder(YourActivity.this)
    .text("Love where you work")
Builder Method Description
session(TwitterSession) Set the TwitterSession of the User to Tweet
image(Uri) Attach an image to the Tweet
text(String) Text to prefill in composer
hashtags(String...) Hashtags to prefill in composer
darkTheme() Use the dark composer theme, defaults to light


After attempting to post a Tweet, the TweetUploadService broadcasts an Intent with the action value for success, for failure or for dismissing the compose dialog. On success, the Intent will contain an extra value with the Tweet ID of the created Tweet. On failure, the Intent will contain a copy of the original intent which could be used to retry the upload. For cancel there is no extra value.

You can create a BroadcastReceiver to receive these Intents.

public class MyResultReceiver extends BroadcastReceiver {
  public void onReceive(Context context, Intent intent) {
    if (TweetUploadService.UPLOAD_SUCCESS.equals(intent.getAction())) {
      // success
      final Long tweetId = intentExtras.getLong(TweetUploadService.EXTRA_TWEET_ID);
    } else if (TweetUploadService.UPLOAD_FAILURE.equals(intent.getAction())) {
      // failure
      final Intent retryIntent = intentExtras.getParcelable(TweetUploadService.EXTRA_RETRY_INTENT);
    } else if (TweetUploadService.TWEET_COMPOSE_CANCEL.equals(intent.getAction())) {
      // cancel

Don’t forget to add your BroadcastReceiver to the application manifest.

    <action android:name=""/>
    <action android:name=""/>
    <action android:name=""/>