0

I'm writing an app with sharing functionality and I want to have a button to share via a specific social media ie. Facebook, without having to open a chooser. Is there anyway to do this? I've been having a look through the source code to see if I can find anything but so far I can't find a way to do this.

Ideally what I would like to do is call the method that the chooser does to get the list of applicable apps to share with and then display a button for the main social media platforms I am targeting. And then when a user clicks one of the buttons it brings them straight to the app with the media loaded so all they have to do is click post to share.

I know using a chooser isn't rocket science but I want the app to be as simple as possible so removing the chooser would be a good step towards it as it would remove a lot of the unnecessary options like email and some of the things that come with the phone that people don't tend use. Although it is likely that I will have the chooser anyway just incase the user wants to share it some other way too, I would like it not to be the only way to share.

A full solution would be awesome but a point in the right direction in terms of where to look in the source code would be great too.

Cob50nm
  • 911
  • 2
  • 9
  • 27

1 Answers1

1

I haven't tested this but have you tried something like this:

Intent fb = new Intent(Intent.ACTION_SEND);
fb.sharingIntent.setClassName("com.facebook.katana", "com.facebook.katana.ShareLinkActivity");
fb.putExtra(Intent.EXTRA_TEXT, "message");

Intent twitter = new Intent(Intent.ACTION_SEND);
twitter.setClassName("com.twitter.android","com.twitter.android.PostActivity");
twitter.putExtra(Intent.EXTRA_TEXT, "message");

Intent intent = Intent.createChooser(fb, "Share");
intent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {
    twitter, ....more here
});
startActivity(intent);

Base on this answer: How to force Share Intent to open a specific app?

Since these activities can change try the url as well or whatever is documented in their website so it fallbacks to their android intents if installed.

Community
  • 1
  • 1
Faisal
  • 2,276
  • 15
  • 19
  • Thanks, this seems to be the right way of going about it, At present I am only showing the buttons to share if the relevant app is installed so the fall back shouldn't be needed. I will accept answer when I have it working to make sure it is is the right way of going about it, incase others are looking for it in the future. – Cob50nm Aug 06 '13 at 17:23
  • This was the right way to do it, had to read through some of the stuff linked to get it fully working and had to make a function to read the activity from the information gotten from the code below. using the code below rather than declaring them statically `Intent intent = new Intent(android.content.Intent.ACTION_SEND); intent.setType("image/*"); List resInfo = getPackageManager().queryIntentActivities(intent, 0);` – Cob50nm Aug 07 '13 at 12:05