Support

AddThis for Android Documentation

Quickstart Guide | Documentation

The AddThis Android SDK allows native Android application developers to share content to destinations across the web, much as the Javascript library allows web developers to share content from their web applications. The Android SDK also has support for sharing image data directly to services that support it. As with all AddThis offerings, we're developing analytics reports to help you understand how your content is being shared.

Please refer to the Quick Start Guide to get up and running quickly with the SDK, including registration, obtaining application IDs, and setting up any necessary service-specific keys.

 

What Can Be Shared?

The Android SDK, like the AddThis web tools, primarily supports sharing URL-based content. That is, you are sharing a URL that is publicly navigable. Many services are also able to inspect URLs to provide rich preview and other media-related capabilities.

The SDK also allows you to share image data directly to a subset of services that support it.

Performing Sharing Operations

The SDK is set up to allow you to include sharing in your application in a few different ways, with varying degrees of customization. Generally, the use-cases are:

  • Share Button: You include an AddThis sharing button in your application in a specified location. This button invokes a menu of personalized choices for the user.
  • Share Menu: You invoke the AddThis sharing menu from your application at a specified location. This is similar to the button mode, but the trigger that invokes the menu is your own.
  • Custom Share Menu: You obtain the appropriate list of services from the SDK, then build your own sharing menu for the user.
  • Service-Specific Share Triggers: you build your own interface to present sharing options, and use the SDK only to initiate the share to a specific service.

No matter which method you chose to use to integrate sharing into your application, URL tracking will be enabled and any library-defined customizations will be honored.

Share Button

You can include the default AddThis share button, which will render the full sharing menu when clicked, in your view as follows:

Method 1:

Place the button in xml:

<com.addthis.ui.views.ATButton android:id="@+id/addthisButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />

Assign the share item to the button:

ATButton btn = (ATButton)findViewById(R.id.addthisButton);
ATShareItem item = new ATShareItem("http://www.addthis.com","Title","Description");
btn.setItem(item);

Method 2:

Create the AddThis button in code and add to the layout.

ATButton btn = new ATButton(context,"http://www.addthis.com","Title","Description");
addContentView(btn, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));

Share Menu

You can include the AddThis sharing menu directly, rendering it from within your own UI control callback, like this:

AddThis.presentAddThisMenu(this,"http://www.addthis.com","Title","Description");

Share to a particular service

To skip the AddThis sharing button or menu altogether, and just use AddThis to share directly to a specific service from your own UI callback, do the following:

AddThis.shareItem(this, "twitter", "http://www.addthis.com","Title","Description");

Sharing Images

You can share image data in much the same way that you can share URLs – the general API support model is identical, though in general you will pass a Bitmap object in place of the urlstring parameter, and the method will be named slightly differently.

Note that not all services support image sharing, so you do need to be attentive when invoking individual services directly. Also, sharing of images to Facebook requires Connect, and Twitter requires OAuth and Twitpic, so if you wish to use these services you need to configure those services.

The corresponding image sharing methods are given below:

Share Button:
ATButton btn = new ATButton(context,"Title","Description",imageBitmap);
addContentView(btn, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));

Share Menu:
AddThis.presentAddThisMenu(this,"Title","Description",imageBitmap);

Share to a particular service:
AddThis.shareItem(this, "twitter",Title","Description",imageBitmap);

About Sharing Services

The AddThis Android SDK supports a large variety of services – places to which you can send content. There are generally four different types of sharing services supported:

Browserless Services

Services that support some type of direct sharing option, leveraging Android libraries, direct integrations, and some likely authentication step. Services in this category include:

  • Facebook (optionally uses Connect, requires some setup)
  • Twitter (optionally uses OAuth, requires some setup)
Native Device Services

Some services are native on the device. These include:

  • Native email (user has to setup an email account in the device to use this)
Browser-based Services

All other services fall into this category; the share takes place in an embedded web view, invoking the OExchange-compliant AddThis Sharing API and with a look and feel similar to the default experience of the AddThis in-page tools. Services in this category include all services supported by the AddThis platform.

Image-aware services

Additionally, some services can support receiving image data rather than URLs. This is a different model, and does not include analytics, but may prove useful in some cases.

 

Services in this category include:

  • Facebook
  • Tumblr
  • Native email
  • Twitter (through Twitpic)

Controlling the Services in the Sharing Menu

The full sharing menu includes a default list of services, determined by AddThis. These services can be modified by the user to better fit their personal preferences. You can also explicitly control the services presented here via setFavoriteMenuServices.

You can also set a list of services as blacklisted using the call: setBlackListedServices. The blacklisted services will not be shown in the service menu list and direct sharing to these services will give an error condition.

Obtaining Services

Certain services are included in native code and are not dynamically included. The SDK obtains the list of other available backend services from the AddThis service API, caching results for 30 days. If you would like to force a refresh of this supported service list, the startServiceUpdate(context) call will do so. You can also disable automatic updates of the service list via setting the value Config.configObject().setAutoUpdate(false); using com.addthis.core.Config object.

If you are building your own sharing menus and just want to obtain available services from the library, you can fetch them like so:

ATServiceList allServices = AddThis.getAllServices();

This will will return you an arraylist of ATService and to share to a particular service you can use:

AddThis.shareItem(this, "twitter", "http://www.addthis.com","Title","Description");

Configuration and Customization

The configurations and customization can be changed by changing the values given in Config and the resources files : strings.xml, colors.xml.

com.addthis.core.Config

Config.configObject().setAddRemoveFavServices(true);
Set this value to true if the user can add or remove services to the favorite service list.

Config.configObject().setAutoUpdate(true);
Set this value to true if the SDK should update the service list database periodically. The update will take place at every 30days or according to the value given in setAutoUpdateInterval()

Config.configObject().setAutoUpdateInterval(10000L);
This is the time interval taken for the periodic updation of the service list. The time is in milliseconds. setAutoUpdate() should be true for this value to take effect.

Config.configObject().setTwitterViaText("addthis");
The text assigned here will be the via text shown along with the tweets. The default value is addthis.

Config.configObject().setShouldShowMoreServices(false);
Set this value to false if you do not want to show the 'More' services view in the AddThis menu.

Config.configObject().setActionBarFont("DroidSans");
Config.configObject().setListViewFont("DroidSans");
Config.configObject().setInfoViewFont("DroidSans");
You can set the font for the action bar, list view and the info view items though these values.

Configuring Service Keys

To leverage the native integrations with Facebook and Twitter, you need to provide your Facebook and Twitter API keys. To share images to Twitter, you'll also need to provide your TwitPic key.

Providing your Facebook key

To use Facebook Connect-enabled sharing, you'll need to tell the library to do so, and then configure your Facebook API key in Config.

You can do both as follows:

Config.configObject().setShouldUseFacebookConnect(true);
Config.configObject().setFacebookAppId("yourkey");

If you don't have a Connect key already, get one from Facebook.

Providing your Twitter keys

To use Twitter OAuth-enabled sharing, you'll need to tell the library to do so, and then configure your Twitter consumer key, consumer secret, and callback URL. You can do both as follows:

Config.configObject().setShouldUseTwitterOAuth(true);
Config.configObject().setTwitterConsumerKey("yourconsumerkey");
Config.configObject().setTwitterConsumerSecret("yourconsumersecret");
Config.configObject().setTwitterCallbackUrl("yourcallbackurl");

If you are not already set up with a Twitter key and secret, follow these steps to get the keys and to set the callback URL. You should select 'browser' as the application type when asked. Note that the callback URL doesn't need to be an existing URL, but it should be entered. If you also want to share an image through Twitter, which will internally use TwitPic, you should obtain and then provide your TwitPic API key to the library:

Config.configObject().setTwitPicApiKey("yourapikey");

Last Updated: Oct 25, 2013 04:18PM EDT
help@addthis.com
http://assets03.desk.com/
false
desk
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
false
Invalid characters found
/customer/en/portal/articles/autocomplete