Problem Solver

How To Remove The Facebook Android Sharing Intent

By , 2 May 2014

How To Remove The Facebook Android Sharing Intent
How To Remove The Facebook Android Sharing Intent

I don't really care why Facebook made a mess of their Android sharing intent. Other developers have already pointed out that their iOS sharing works fine, but their Android product only allows you to share URLs and not text. My guess is they are trying to force developers onto their API because, you know, force makes people so much more motivated and creative and all that.

Whatever.

The real problem is that it makes your app look broken, and fortunately there is a simple solution:

Dump Facebook.

Just cut and paste the code below to launch your share intents and Facebook will not be listed as an option. That way you won't look bad when their share page comes up blank.

How To Remove The Facebook Android Sharing Intent
    // get available share intents
    List<Intent> targets = new ArrayList<Intent>();
    Intent template = new Intent(Intent.ACTION_SEND);
    template.setType("text/plain");
    List<ResolveInfo> candidates = this.getPackageManager().
	  queryIntentActivities(template, 0);

    // remove facebook which has a broken share intent
    for (ResolveInfo candidate : candidates) {
        String packageName = candidate.activityInfo.packageName;
        if (!packageName.equals("com.facebook.katana")) {
	  Intent target = new Intent(android.content.Intent.ACTION_SEND);
	  target.setType("text/plain");
	  target.putExtra(Intent.EXTRA_TEXT, "Text to share"));
	  target.setPackage(packageName);
	  targets.add(target);
        }
    }
    Intent chooser = Intent.createChooser(targets.remove(0), translate("Share Via"));
    chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, targets.toArray(new Parcelable[]{}));
    startActivity(chooser);
 

About Roger Keays

How To Remove The Facebook Android Sharing Intent

I am an artist, an engineer, and a student of psychology. Some projects I'm working on at the moment are Sunburnt SEO, The Game Of Your Life, Money Talks and other, top secret stuff. You can follow me via RSS or on Twitter, Facebook, and even Google+.

Add a comment

Please visit http://RogerKeays.com/how-to-remove-the-facebook-android-sharing-intent to add your comments.

Comment posted by: Simon, 4 months ago

Very helpful, thanks a lot !

Follow Roger Keays

It'll Change Your Life

I write every Sunday about all sorts of interesting stuff. Drop me your email and you'll be the first to get my articles when they're published. It'll change your life. And it's free :)


Website Updates

Latest Poll

Is your life is better or worse because of Facebook?
Better
Worse
The same