Sarvan
Sarvan

Reputation: 61

How to use facebook share inside the recyclerview

I need to share my app link on Facebook, but I don't know how to call share dialog and onactivityresult method inside the recyclerview adapter.

Upvotes: 0

Views: 181

Answers (1)

Raunak Verma
Raunak Verma

Reputation: 211

You cannot share text alone without using Facebook SDK

Facebook ignores plain text sharing using intents, BUT you can share any url.

Note:-if you share text it wont show there, but url will show, you can share simple image or video though

Use the following code in your recyclerview adapter

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "http://www.google.com");
PackageManager pm = getApplicationContext().getPackageManager();
for (final ResolveInfo app : activityList)
{
  if ((app.activityInfo.name).startsWith("com.whatsapp"))// for facebook("com.facebook.katana") but it wont work use SDK
  {
   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);
   getApplicationContext().startActivity(shareIntent);
   break;
   }
 }

Here is the link where you can learn in deep about Facebook SDK and how can you share content from your android app to facebook

Upvotes: 1

Related Questions