Android Share Intent chooser - Sharing TEXT with Facebook/Twitter Social media etc

14,579

Solution 1

this depends upon what intent filters are defined by each of those apps.
For instance if I add intent-filter android.intent.action.send

If I choose single image from Gallery my application will appear in the list. However if I choose multiple my application will not appear as I have not added the intent-filer for android.intent.action.send_multiple

So it depends upon what intents facebook is filtering for. You need to see the release notes or help or developer pages for that.

Solution 2

Also it should be "text/plain" and not "plain/text" according to the documentation.

Solution 3

The facebook issue is a limitation in facebook permissions. Use the facebook API

Solution 4

Share via Twitter :

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");

shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, (String)v.getTag(R.string.app_name));

shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, (String)v.getTag(R.drawable.ic_launcher));

// for finding twitter package name ---- >>

   PackageManager pm = v.getContext().getPackageManager();

   List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);

     for (final ResolveInfo app : activityList) 
      {
        if ("com.twitter.android.PostActivity".equals(app.activityInfo.name))
          {
             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;
          }
        }

Share via Facebook

   Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
   shareIntent.setType("text/plain");
   shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,String)v.getTag(R.string.app_name));

   shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, (String) 

v.getTag(R.drawable.ic_launcher));

// finding facebook package name 

   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;
        }
      }

Share via Gmail

  Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);

   shareIntent.setType("text/plain");         

shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT(String)v.getTag(R.string.app_name));

 shareIntent.putExtra(android.content.Intent.EXTRA_TEXT(String)v.getTag(R.drawable.ic_launcher));

// finding gmail package name  --- 

  PackageManager pm = v.getContext().getPackageManager();

   List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);

       for (final ResolveInfo app : activityList) 
        {
          if ((app.activityInfo.name).contains("gmail")) 
           {
             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;
           }
       }
Share:
14,579
tiptopjat
Author by

tiptopjat

Android dev noob

Updated on July 28, 2022

Comments

  • tiptopjat
    tiptopjat almost 2 years

    If I only send text, the Share Intent chooser DOES NOT give Facebook/Twitter as an option.

    Only Gmail, Skype and Evernote are options.

    Here is my code

    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    
    shareIntent.setType("plain/text");
    shareIntent.putExtra(Intent.EXTRA_TEXT, text)
    startActivity(Intent.createChooser(shareIntent, "Share using"));
    

    I have tried different combination of setType() with no joy including "text/*", "text/html" and passing HTML text in the putExtra as follows:

    shareIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("<p>This is the text that will be shared.</p>"));
    

    When I use "text/plain", Facebook comes up as an option but the text does not load up when selecting it. But the text does load for Twitter,email, SMS.

    Has anyone else encountered this problem?

    When I share an image, there is no problem and Facebook along with other social media apps are available on the list.