1

I am doing an android share intent for Pinterest but is not fully working. I am able to attach the image but I can't send text to the "description" field in the share window. I've tried different types (text/plain, image/*, image/png) and also tried the ACTION_SEND_MULTIPLE intent type but still no luck. Google chrome share intent works perfectly so I'm sure Pinterest supports this functionality. Here is my code:

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("*/*");
    intent.putExtra(Intent.EXTRA_TEXT, text);
    if(file != null) intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
    intent.setClassName(packageName, name);

    this.startActivity(intent);

Any idea? thanks!

memozac
  • 91
  • 2
  • 7

3 Answers3

14

I found a way to share to Pinterest with plain Android intents (without using the Pinterest SDK), with help from Pin It button developer docs.

Basically you just open an URL like this with Intent.ACTION_VIEW; the official Pinterest app kindly supports these URLs. (I've earlier used a very similar approach for sharing to Twitter.)

https://www.pinterest.com/pin/create/button/
   ?url=http%3A%2F%2Fwww.flickr.com%2Fphotos%2Fkentbrew%2F6851755809%2F             
   &media=http%3A%2F%2Ffarm8.staticflickr.com%2F7027%2F6851755809_df5b2051c9_z.jpg
   &description=Next%20stop%3A%20Pinterest

And for smoother user experience, set the intent to open directly in Pinterest app, if installed.

A complete example:

String shareUrl = "https://stackoverflow.com/questions/27388056/";
String mediaUrl = "http://cdn.sstatic.net/stackexchange/img/logos/so/so-logo.png";
String description = "Pinterest sharing using Android intents"
String url = String.format(
    "https://www.pinterest.com/pin/create/button/?url=%s&media=%s&description=%s", 
     urlEncode(shareUrl), urlEncode(mediaUrl), urlEncode(description));
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
filterByPackageName(context, intent, "com.pinterest");
context.startActivity(intent);

Util methods used above:

public static void filterByPackageName(Context context, Intent intent, String prefix) {
    List<ResolveInfo> matches = context.getPackageManager().queryIntentActivities(intent, 0);
    for (ResolveInfo info : matches) {
        if (info.activityInfo.packageName.toLowerCase().startsWith(prefix)) {
            intent.setPackage(info.activityInfo.packageName);
            return;
        }
    }
}

public static String urlEncode(String s) {
    try {
        return URLEncoder.encode(s, "UTF-8");
    }
    catch (UnsupportedEncodingException e) {
        Log.wtf("", "UTF-8 should always be supported", e);
        return "";
    }
}

This is the result on a Nexus 5 with Pinterest app installed:

And if Pinterest app is not installed, sharing works just fine via a browser too:

Community
  • 1
  • 1
Jonik
  • 80,077
  • 70
  • 264
  • 372
  • Have you ever figured out a way to share local images using the method above. I am having a tough time figuring out how to send a URL for the image (The website field in the pin) along with an image and description. Here's my related question - http://stackoverflow.com/questions/35561031/android-pinterest-share-intent-with-website – user1689757 Feb 25 '16 at 22:52
  • Is it possible to share image from SD card using this method? If I change `mediaUrl` into my file path then pinterest shows notification that, image saving failed. – Mazedul Islam Nov 19 '17 at 09:31
1

for some reason pinterest app doesn't comply to the standard (Intent.EXTRA_TEXT) so we have to add it separately

if(appInfo.activityInfo.packageName.contains("com.pinterest"){
        shareIntent.putExtra("com.pinterest.EXTRA_DESCRIPTION","your description");
}
Saqib
  • 1,737
  • 2
  • 19
  • 30
1
File imageFileToShare = new File(orgimagefilePath);

Uri uri = Uri.fromFile(imageFileToShare);

Intent sharePintrestIntent = new Intent(Intent.ACTION_SEND);
sharePintrestIntent.setPackage("com.pinterest");
sharePintrestIntent.putExtra("com.pinterest.EXTRA_DESCRIPTION", text);
sharePintrestIntent.putExtra(Intent.EXTRA_STREAM, uri);
sharePintrestIntent.setType("image/*");
startActivityForResult(sharePintrestIntent, PINTEREST);
Ram Suthakar
  • 275
  • 2
  • 15
Eshack Nazir
  • 354
  • 3
  • 16