Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android direct shared

I am trying to share a link from my app with direct share. The share dialog must be like the image below with the most used contacts from messaging apps, like WhatsApp contacts.

Goal which I am trying to achieve

This is the Intent structure which I am using for share the link:

 Intent shareIntent = ShareCompat.IntentBuilder
                        .from(getActivity())
                        .setType("text/plain")
                        .setText(sTitle+ "\n" + urlPost)
                        .getIntent();
                if (shareIntent.resolveActivity(
                        getActivity().getPackageManager()) != null)
                    startActivity(shareIntent);

And this is what my app shows:

what my app shows

Any idea how to achieve that?

like image 429
cherif Avatar asked Mar 02 '16 23:03

cherif


People also ask

What is direct share on my Android?

Direct Share is a feature that allows apps to show app-specific options directly in the system Intent chooser dialog. Users can then jump directly into your app when sharing content from another app.

What happens if I turn off direct share?

Once disabled, you will no longer see suggestions to share to individual contacts in apps, and your share menu will be restored to only show app and app actions (with no pesky re-flowing, either).


2 Answers

You should use .createChooserIntent() instead of .getIntent()

like image 119
German Avatar answered Oct 07 '22 16:10

German


Like this code below, you can use Intent.createChooser

            Intent sharingIntent = new Intent(Intent.ACTION_SEND);
            Uri screenshotUri = Uri.parse("file://" + filePath);

            sharingIntent.setType("image/png");
            sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
            startActivity(Intent.createChooser(sharingIntent, "Share image using"));
like image 1
Ken Avatar answered Oct 07 '22 16:10

Ken