Reputation: 1
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;
}
}
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.
Upvotes: 0
Views: 2884
Reputation: 4781
You acheive this by setting the package name in the intent.
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.
// Using Facebook App
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);
// Using Facebook Lite App
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...
NOTE : Facebook share will work fine at its best when using the Facebook SDK (use version greater than 4.X - recommended )
Upvotes: 3
Reputation: 2405
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, activity.getString(R.string.share_subject));
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Example text");
activity.startActivity(Intent.createChooser(shareIntent, activity.getString(R.string.share_title)));
Upvotes: 0