Compose Tweets

The TweetComposer Kit 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 App Card Composer - a lightweight composer which lets users compose Tweets with App Cards from within your application.

Set Up Kit


Skip this section if you installed Twitter Kit using the Twitter Kit installation instructions.

Add the TweetComposer Kit to your build.gradle dependencies. View the TweetComposer changelog for the latest version number.

dependencies {
    compile('') {
        transitive = true;

and be sure the TweetComposer Kit is included in your application’s Fabric.with() call.


public void onCreate() {

    TwitterAuthConfig authConfig =  new TwitterAuthConfig("consumerKey", "consumerSecret");
    Fabric.with(this, new TwitterCore(authConfig), new TweetComposer());

Compose a Tweet

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

Build an Intent

After initializing the TweetComposer Kit with Fabric, start construction of a Tweet composer by using the Builder.


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

The image Uri should be a file Uri (i.e. file://absolute_path scheme) to a local file. For example,

File myImageFile = new File("/path/to/image");
Uri myImageUri = Uri.fromFile(myImageFile);


If the Twitter app is not installed, the intent will launch in a browser, but the specified image will be ignored.

Twitter Kit App Card Composer

The Twitter Kit App Card Composer is a lightweight composer which lets users compose Tweets with App Cards 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 ComposerActivity and include the TwitterSession.

final TwitterSession session = TwitterCore.getInstance().getSessionManager()
final Intent intent = new ComposerActivity.Builder(YourActivity.this)
Builder Method Description
session(TwitterSession) Set the TwitterSession of the User to Tweet
card(Card) Attach an App Card to the Tweet
hashtags(hashtags...) Hashtags to prefill in composer
darkTheme() Use the dark composer theme, defaults to light

App Cards

If you’d like to attach an Application Card to the Tweet, create a Card with the AppCardBuilder.

A live Google Play Store Android package name is required for an App Card to be rendered in the Twitter App. The Builder automatically detects your application’s package name (e.g. “”) from the context argument.

final Card card = new Card.AppCardBuilder(YourActivity.this)
Builder Method Description
imageUri(uri) Sets the App Card image Uri
iPhoneId(id) Set the iPhone app Id from the Apple App Store
iPadId(id) Set the iPad app Id from the Apple App Store
googlePlayId(package) Override the detected app package name

Include the card in the Intent to ComposerActivity.

final Intent intent = new ComposerActivity.Builder(YourActivity.this)
    .hashtags("#fabric", "#twitter")



Your application must first be whitelisted by Twitter in order to post a Tweet with an App Card. Please review App Card Composer Usage Guidelines for requesting access.

App Cards have several requirements:

  • Specify a Card image Uri to a local media file on the device.
  • Specify the package name of a live Google Play application.
  • The Card image must be at least 800 pixels wide and 420 pixels tall, otherwise the Card won’t be rendered in the Twitter Android and iOS apps.
  • We recommend an aspect ratio of 1.91:1 to provide the best rendering. Other aspect ratios will be cropped.
  • Card must comply with App Card Composer Usage Guidelines.


After attempting to post a Tweet, the ComposerActivity TweetUploadService broadcasts an Intent with the action value for success or for failure. 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.

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 {
      // failure
      final Intent retryIntent = intentExtras.getParcelable(TweetUploadService.EXTRA_RETRY_INTENT);

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

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