Search code examples
androidshareshareactionprovider

Share in Android


I'm working on a simple app and need to add share feature to it. I just need to share result of the game on FB, Twitter and G+. If anyone can help, how can I implement this into my app? Thanks in advance..


Solution

  • You can try something like this. Usually, FB, Twitter, and Google+ listen to share event

    public void share() {
        Intent i = null;
        String msg ="Something to share about"
    
        i = new Intent(Intent.ACTION_SEND);
        i.setType("text/plain");
    
        i.putExtra(Intent.EXTRA_TEXT, msg);
        i.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.sharing_sbj) + " \""
                + "Share title"+ "\" : " + getResources().getString(R.string.app_name));
    
        startActivity(Intent.createChooser(i, this.getString(R.string.sending_to)));
    }