如何在Facebook上分享文字和图片,我正在编写一个教会应用程序,我希望允许用户与URL共享文本和图像。
我可以分享在线应用链接,但无法分享文字&图像,我在哪里?
我的代码如下:
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);
}
}
}
});
答案 0 :(得分:3)
通过意图选择器在android中使用此共享网址 ... 你不直接在Facebook wallpost上分享任何文字
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String urlToShare = "www.google.com";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
// intent.putExtra(Intent.EXTRA_SUBJECT, "Foo bar"); // NB:
// has no effect!
intent.putExtra(Intent.EXTRA_TEXT, urlToShare);
// See if official Facebook app is found
boolean facebookAppFound = false;
List<ResolveInfo> matches = getPackageManager()
.queryIntentActivities(intent, 0);
for (ResolveInfo info : matches) {
if (info.activityInfo.packageName.toLowerCase()
.startsWith("com.facebook.katana")) {
intent.setPackage(info.activityInfo.packageName);
facebookAppFound = true;
break;
}
}
// As fallback, launch sharer.php in a browser
if (!facebookAppFound) {
String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u="
+ urlToShare;
intent = new Intent(Intent.ACTION_VIEW, Uri
.parse(sharerUrl));
}
startActivity(intent);
}
});
答案 1 :(得分:3)
嘿,当我问同样的question
时,我做了很多研究基本上,使用软件包名称“com.facebook.katana”无法从facebook应用程序中进行操作,因为它会在图像显示时忽略额外文本,但实际上bug会看到此文件,但在图像时可以有链接不在这里。我知道很烦人。
经过大量的关注后,我使用facebook sdk 3.14.1创建了我自己的活动,它允许图像和文本在这里是演示项目的github link给它一个去,让我们知道它是否有助于你