Home » Android » android – Samsung devices automatically set default application for share Intent

android – Samsung devices automatically set default application for share Intent

Posted by: admin June 15, 2020 Leave a comment

Questions:

I have a function in my app that let’s people share content.

The way it usually works is:

Device asks user to choose an app to handle the Intent. The user can choose between ‘just once’ or ‘always’.

On some Samsung devices, e.g. Galaxy S6, the ‘just once’ and ‘always’ options are missing, after selection of an app this app becomes the standard for that event.

This even leads to my app being freshly installed, when trying to share, the user is not asked at all, the Intent is just handled by the app that the user selected for sharing when sharing from another app!

This problem with some Samsung devices is documented here and here.

This is how I construct my simple intent:

Intent intent = ShareCompat.IntentBuilder.from(this)
        .setSubject("mySubject")
        .setText("myText")
        .setType("text/plain")
        .setChooserTitle("myChooserTitle").getIntent();

startActivity(intent);

I also tried:

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "myText");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "mySubject");
sendIntent.setType("text/plain");

startActivity(sendIntent);

My question is: can I do anything from my code to prevent this or do I have to tell my users not to buy a Samsung next time?

How to&Answers:

The following fixed the problem:

startActivity(Intent.createChooser(sendIntent, "title"));