问题描述
Am使用以下代码直接将内容共享到Facebook应用,
Am using the following code for sharing the content directly to facebook app,
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent
.putExtra(
android.content.Intent.EXTRA_TEXT,
"Some text");
PackageManager pm = v.getContext().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);
v.getContext().startActivity(shareIntent);
break;
}
}
它非常适合Facebook应用,但是面临着lite应用的问题.对于安装了facebook-lite不能共享内容的用户,它仅显示fb-lite应用程序的启动屏幕.请帮帮我.
it is working perfectly for facebook app, but facing issues with facebook lite app. For user who installed facebook-lite not able to share the content, It simply display the splash screen of fb-lite app. Please help me out.
推荐答案
您可以通过在意图中设置程序包名称来实现此目的.
You acheive this by setting the package name in the intent.
它将查找指定的应用程序;如果存在,它将打开该应用程序.否则,它将显示错误消息,提示没有应用可以执行此操作.尝试使用Android默认意图进行共享的方法.
It will look for the specified app, If present it will open the app. other wise it will show the error message that there is no app can perform this action.Try the approach for sharing using the Android default intent.
//使用Facebook应用
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Example text");
intent.setPackage("com.facebook.katana");
activity.startActivity(intent);
//使用Facebook Lite应用
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Example text");
intent.setPackage("com.facebook.lite");
activity.startActivity(intent);
让我知道它是怎么回事...
Let me know how it goes...
注意:使用Facebook SDK(使用大于4.X的版本-推荐使用)时,Facebook共享将达到最佳状态
这篇关于使用Intent共享内容至Facebook Lite Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!