Android的份额意图Pinterest的不工作 [英] Android share intent for Pinterest not working

查看:124
本文介绍了Android的份额意图Pinterest的不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了Pinterest的一款Android份额意图,但没有完全工作。我可以附加图像,但我不能发送文本的说明字段中的份额窗口。我已经尝试了不同类型(文本/纯,影像/ *,图像/ PNG),也试过ACTION_SEND_MULTIPLE意图类型,但仍然没有运气。谷歌Chrome浏览器份额的意图完美的作品,所以我敢肯定,Pinterest的支持此功能。这是我的code:

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!

推荐答案

我发现了一种与普通的Andr​​oid意图分享到Pinterest的(不使用的 Pinterest的SDK ),从别起来按钮开发文档帮助。

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.

基本上你只打开一个这样的URL以 Intent.ACTION_VIEW ;官方Pinterest的应用程序亲切支持这些URL。 (我以前用过一个非常类似的方法<一href="http://stackoverflow.com/questions/2077008/android-intent-for-twitter-application/21186753#21186753">sharing到Twitter 。)

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

和流畅的用户体验,<一个href="http://developer.android.com/reference/android/content/Intent.html#setPackage(java.lang.String)">set意图直接在Pinterest的应用程序打开,如果安装了。

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

一个完整的例子:

String shareUrl = "http://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), description);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
filterByPackageName(context, intent, "com.pinterest");
context.startActivity(intent);

上面使用的Util方法:

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 "";
    }
}

这是一台Nexus 5与Pinterest的应用程序安装的结果是:

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

如果Pinterest的应用程序是的没有的安装,共享通过浏览器工作得很好过:

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

这篇关于Android的份额意图Pinterest的不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆