我做了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!
我发现了一种与普通的Android意图分享到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。 (我以前用过一个非常类似的方法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://m.xsw88.com/allimgs/daicuo/20230903/5776.png.jpg
&description=Next%20stop%3A%20Pinterest
和流畅的用户体验,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 = "https://m.xsw88.com/allimgs/daicuo/20230903/5777.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: