如何在Facebook上使用Intent共享文本和图像 [英] How to share Text and Image on Facebook using Intent
问题描述
如何在Facebook上共享文本和图像,我正在写一个教会应用程序,其中我想允许用户与URL一起共享文本和图像。
How to share Text and Image on Facebook, I am writing a Church Application in which i want to allow user to share text and image along with URL.
我能够分享在线应用程序链接,但无法共享文本和图像,我失踪了?
I am able to share online app link but not able to share text & image, where i am missing ?
我的代码如下所示:
Button btnFbSharing = (Button) findViewById(R.id.fbSharing);
btnFbSharing.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_TITLE, "Church Application");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "https://play.google.com/store/apps/details?id=com.facebook.katana");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "A new world begin");
shareIntent.putExtra(android.content.Intent.EXTRA_STREAM, R.drawable.ic_launcher);
PackageManager pm = getApplicationContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList) {
if ((app.activityInfo.name).contains("facebook")) {
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(
activity.applicationInfo.packageName,
activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
startActivity(shareIntent);
}
}
}
});
推荐答案
嘿,我做了很多研究,问了相同的问题
Hey I did a lot of research into this as I asked the same question
基本上,使用包名称com.facebook.katana的Facebook应用程序是不可能的,因为当图像出现时,它忽略了额外的文字,因此实际错误,但当图像不存在时可以有链接。非常讨厌我知道。
Basically it is not possible from the facebook app using the package name "com.facebook.katana" as it ignores the extra text when the image is there see this for actual bug but can have links when the image is not there. Very annoying I know.
经过很多关于我使用Facebook sdk 3.14.1创建了我自己的活动,它允许图像和文本在这里是 github链接到演示项目,让它走一走,知道如果它帮助你。
After a lot of looking about I created my own activity using the facebook sdk 3.14.1 which allows images and text here is the github link to the demo project give it a go and let know if it helps you out.
这篇关于如何在Facebook上使用Intent共享文本和图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!