2

I want to share the content from my application to other applications. I've used the below code for this

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, title);
intent.putExtra(Intent.EXTRA_TEXT, linkUrl);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
((Activity) mContext).startActivityForResult(
            Intent.createChooser(intent, mContext.getString(R.string.share_via) + "…"), ConstantVariables.CONTENT_SHARING_CODE)

I've also defined the below intent filter in my application's manifest file.

<intent-filter>
            <action android:name="android.intent.action.SEND" />

            <category android:name="android.intent.category.DEFAULT" />

            <data android:mimeType="image/*" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.SEND" />

            <category android:name="android.intent.category.DEFAULT" />

            <data android:mimeType="text/plain" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.SEND_MULTIPLE" />

            <category android:name="android.intent.category.DEFAULT" />

            <data android:mimeType="image/*" />
        </intent-filter>

So, whenever I share any content from my application, an application chooser appears which lists all the apps which can receive this content. In this listing, my application is also getting listed but I don't want to list my application when I share any content from my app itself.

Can someone please help, how can I achieve this.

Thanks a lot in advanced.

Prithniraj Nicyone
  • 5,021
  • 13
  • 52
  • 78

1 Answers1

0

Look the below code.. taken from my previous answer

 public static void shareExludingApp(Context ctx, String packageNameToExclude, android.net.Uri imagePath, String text) {

            List<Intent> targetedShareIntents = new ArrayList<Intent>();
            Intent share = new Intent(android.content.Intent.ACTION_SEND);
            share.setType("image/*");
            File file = new File(imagePath.getPath());
            List<ResolveInfo> resInfo = ctx.getPackageManager().queryIntentActivities(createShareIntent(text, file), 0);
            if (!resInfo.isEmpty()) {
                for (ResolveInfo info : resInfo) {
                    Intent targetedShare = createShareIntent(text, file);

                    if (!info.activityInfo.packageName.equalsIgnoreCase(packageNameToExclude)) {
                        targetedShare.setPackage(info.activityInfo.packageName);
                        targetedShareIntents.add(targetedShare);
                    }
                }

                Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0),
                        "Select app to share");
                chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
                        targetedShareIntents.toArray(new Parcelable[]{}));
                ctx.startActivity(chooserIntent);
            }

        }

        private static Intent createShareIntent(String text, File file) {
            Intent share = new Intent(android.content.Intent.ACTION_SEND);
            share.setType("image/*");
            if (text != null) {
                share.putExtra(Intent.EXTRA_TEXT, text);
            }
            share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
            return share;
        }
Community
  • 1
  • 1
Sahil Manchanda
  • 9,812
  • 4
  • 39
  • 89