Sharing Non-URL ContentΒΆ

If your app has content that does not live on the web (i.e. it does not have URL) you can still allow your users to share this content using a non-URL share.

When the share occurs we will create a webpage for you that renders the content you include in the share item.

Non-URL components of the share item correspond to Open Graph ➚ tags automatically added to the page we create so that post to social networks like Facebook render with the correct text and images you intend.

Note


You can also use the Item described below even if you do have a URL to add more meaning to your analytics

images/og_logo.png

The example below is the same as the Share Dialog example but rather than using a URL for the share data you would use an Item

Instead of this:

final String urlToShare = "http://www.sharethis.com";

Use this:

// This would be the item you are wanting to share...
final Item item = new Item();

// The title corresponds to the og:title meta tag element
// One of title OR url are REQUIRED
item.setTitle("My Article");

// The description corresponds to the og:description meta tag element
item.setDescription("The description of my article");

// Image, video and type are also supported
item.setImageUrl("...");
item.setVideoUrl("...");
item.setType("...");

// You can also add custom tags to the content
item.addTag("Entertainment");
item.addTag("Sports");

The full example looks like this:

final Activity context = this;

// This would be the item you are wanting to share...
final Item item = new Item();

// The title corresponds to the og:title meta tag element
// One of title OR url are REQUIRED
item.setTitle("My article");

// The description corresponds to the og:description meta tag element
item.setDescription("Something to do with my item");

// Set the content type for the intent (*/* means ALL)
final String contentType = "*/*";                       // <== TODO: Set this

// Set the title for the dialog
final String dialogTitle = "Share to...";               // <== TODO: Set this

// Create an intent.  The URL to be shared will be available in the callback below
final Intent shareIntent = new Intent(Intent.ACTION_SEND);

// Set the conent type for the intent (*/* means ALL)
shareIntent.setType(contentType);

// Grab a reference to your share button
Button shareButton = (Button) findViewById(R.id.btnShare);

// Trigger the share dialog on click
shareButton.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {

        // Call the "showShareDialog" endpoint to render the share dialog
        // The listener is used to set the trackable URL on to the share intent.
        Loopy.showShareDialog(context, "Share to...", item, shareIntent, new ShareDialogListener() {

            @Override
            public void onLinkGenerated(Item item, Throwable error) {
                if (error == null) {
                    // We got a tracking shortlink ok, set it in the body of the share (or wherever you like)
                    shareIntent.putExtra(Intent.EXTRA_TEXT, item.getShortlink());
                }
            }
        });
    }
});