8

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?

fweigl
  • 21,278
  • 20
  • 114
  • 205
  • Don't you ussually define this Intent in Manifest, which Activity should be launch via Intent? Probably you have done this, but not seeing it here. Maybe you can define that at specific intent, only your activity should be launched. I don't know of which Intents you're speaking, but I am using NFC Intent (triggered by NDEF on Tag) and it launches my Activity, if it reads out a specific NDEF from the Tag. – David Kasabji Dec 15 '16 at 11:05
  • 1
    @AndroidNFC I don't want my own activity to be launched, but whatever app the user chooses to for sharing some text with someone, e.g. Whatsapp, Email client etc. – fweigl Dec 15 '16 at 12:06

1 Answers1

13

The following fixed the problem:

startActivity(Intent.createChooser(sendIntent, "title"));
fweigl
  • 21,278
  • 20
  • 114
  • 205