Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Android – Sharing data from your app using Intent.ACTION_SEND

Sharing data or content from an app to another is a common requirement but with a twist. So today I am going to discuss several type of content sharing in this article.

There are mainly three ways to share data which depends on requirement, let’s have a look –

  • Sharing to all the available apps using Intent.ACTION_SEND

    This means your app can share content to all the available apps of an Android device those can accept your content, and to implement it you have to use the following Code

    Intent share = new Intent(android.content.Intent.ACTION_SEND);
    // Add data to the intent, the receiving app will decide
    // what to do with it.
    share.putExtra(Intent.EXTRA_SUBJECT,  "Enter your title here");
    share.putExtra(Intent.EXTRA_TEXT, "Enter your description here");
    activity.startActivity(Intent.createChooser(share, "Share"));
  • Sharing to a specific app

    In some cases we only wants to share content to a specific app like Facebook, Twitter,LinkedIn etc. To achieve this use the below mentioned code –

    String packageName = "com.facebook.katana";
    String fullUrl = "";
            Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
            if (intent == null) {
                Intent i = new Intent(Intent.ACTION_VIEW);
            } else {
                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                sharingIntent.setClassName(packageName ,
                sharingIntent.putExtra(Intent.EXTRA_TEXT, "your title text");

    The above code is good to share to Facebook, Twitter or Linked like social apps, whereas if you want to share your app’s data to another app and you know the URI of the other app you can still share without mentioning the activity name using implicit intent similar to the following code –

    String packageName = "com.sample";
            Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
            if (intent == null) {
                intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("market://details?id=" + packageName));
            } else {
                String url = "sample://app/uri";
                try {
                    intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
                } catch (URISyntaxException e) {

    This code will also take care if your intended app is not installed

    Read also –

    • Loading images from SD Card in a ListView
    • Styling custom views in Android
  • Sharing to specific apps using Intent.ACTION_SEND

    Now this is the rarely used requirement where developer only want to show only a few set of apps to share content from their app and to achieve this you have to write little lengthy code

    List targetShareIntents=new ArrayList();
        Intent shareIntent=new Intent();
        List resInfos=getPackageManager().queryIntentActivities(shareIntent, 0);
            System.out.println("Have package");
            for(ResolveInfo resInfo : resInfos){
                String packageName=resInfo.activityInfo.packageName;
                Log.i("Package Name", packageName);
                if(packageName.contains("") || packageName.contains("com.facebook.katana") || packageName.contains("com.kakao.story")){
                    Intent intent=new Intent();
                    intent.setComponent(new ComponentName(packageName,;
                    intent.putExtra(Intent.EXTRA_TEXT, "Text");
                    intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
                System.out.println("Have Intent");
                Intent chooserIntent=Intent.createChooser(targetShareIntents.remove(0), "Choose app to share");
                chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetShareIntents.toArray(new Parcelable[]{}));
                System.out.println("Do not Have Intent");

    The above code will show Facebook, Twitter, Kakao app in the intent chooser to share content.

I hope this article will be helpful to all of you, so do not forget to share it with your friends and colleagues.

Happy coding!!!

The post Android – Sharing data from your app using Intent.ACTION_SEND appeared first on { }.

This post first appeared on Onetouchcode, please read the originial post: here

Share the post

Android – Sharing data from your app using Intent.ACTION_SEND


Subscribe to Onetouchcode

Get updates delivered right to your inbox!

Thank you for your subscription