0

I am developing a game, and I would like to how to send a message and a screenshot to social media while the user will log into his account.

So I have many options:

  1. I use a code like this one to take a screenshot of the current highscore of the user. But the problem is how could I send this picture to social media? Is there a way to send a picture while logging into facebook/twitter?

  2. I read that I could use the facebook APK. But isn't this too much for only posting one message? And if I want twitter too, do I have to use the twitter APK (if existing)?

  3. Should I abandon the idea of sending a screenshot, and use instead only a text message to promote the highscore (and my game with it) ?

Community
  • 1
  • 1
FR073N
  • 2,011
  • 4
  • 29
  • 42

1 Answers1

1

You could use a Share intent to share your image. This will cause Android to show a dialog with all available apps that can share and image. The dialog will contain Facebook, twitter, google plus, SMS, whatsapp etc. if they are installed.

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");// image/png if it's a png

share.putExtra(Intent.EXTRA_STREAM,
  Uri.parse("<path_to_image>"));

startActivity(Intent.createChooser(share, "Share Highscore"));

You will need to save your screenshot somewhere on the external or internal storage and provide the intent with a path to it before this can be done.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
  • 1
    Unfortunately the Facebook App doesn't work correctly with the Share Intent. It's shown in the list but when the app opens the content isn't there -- this is true for images and text. I had a similar problem with my sports tracker app when trying to share a picture of your route. Share intent works fine with Twitter, Google+, Mail etc. but for Facebook I had to go all the way using their SDK :-/ – Ridcully Dec 18 '12 at 19:17
  • Hmm... I've seen the facebook app work with images from the gallery app. Maybe it's something else – Raghav Sood Dec 18 '12 at 19:21
  • I think you're right. The problem is with texts only. As my app posts a summary of the workout and a picture of the route, I needed to share both and the problem is with texts. – Ridcully Dec 18 '12 at 19:26
  • @Raghav I have to post only an image, so this solution should be fine? I will try it, thank you! – FR073N Dec 18 '12 at 19:40
  • @EvilDesire I think it should work fine. Do post back your results. – Raghav Sood Dec 18 '12 at 19:41
  • @Raghav Actually, this function worked fine with DropBox or Email, but not in Facebook nor twitter. In facebook I have the "An error occured during the loading of the photo", and with twitter I don't have the picture. What sould I do? – FR073N Dec 18 '12 at 22:03
  • 1
    @Raghav I found the problem. To use the cope sample you past, the image must be in the media library. If not there will be problem sharing the image. Solution is here http://stackoverflow.com/questions/2206397/android-intent-action-send-with-extra-stream-doesnt-attach-any-image-when-choo – FR073N Dec 19 '12 at 21:14