How to implement ‘Tell a friend’ action

Many times we need to share a link or other information with our friends or other users. It can be the case when we want to share our application link with other users.

tell a friend
We want to allow the user to chose how to share this information using Facebook, Twitter or simply SMS or email.
The first step is to create an Intent with SEND action like that :

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

Next we need to set the content-type so that the system can chose the application that can handle this content-type, in our case we need text/plain.


It’s time we set the body of our message and the subject if the application supports it:

sharingIntent.putExtra(Intent.EXTRA_TEXT, "Here the body");
Please notice that in case the user choses for example SMS or Twitter the body shouldn’t be more than 140 chars. For example if you want to send a link you should use a shorten link service.  and the subject (if supoorted)
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject here");
Now we simply need to launch our action
startActivity(Intent.createChooser(sharingIntent, "How do you want to share?"));
The result is shown below:




If we chose, for example, Gmail app we will get:

var currentposturl=””;
var maxresults=4;
var relatedpoststitle=”Related Posts :”;


More posts...

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.