Problem with sharing

0

I used the following code to capture text and share.

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
String texto = "Olá sou um texto compartilhado"
sendIntent.putExtra(Intent.EXTRA_TEXT, texto);
sendIntent.setType("text/plain");
startActivity(sendIntent);

When I ran the first time it correctly opened the share containing all applications. When I run it again it goes straight to the app I chose the first time. It's as if he's been saved. But I want it to always open the share to choose. How do I resolve this?

    
asked by anonymous 04.07.2018 / 02:37

2 answers

2

To resolve this problem, you must open the sharing options to choose which app you want to share the text with. That way the code below works for what was proposed.

Intent sendIntent = new Intent(Intent.ACTION_SEND);
String texto = "Olá sou um texto compartilhado";
sendIntent.putExtra(Intent.EXTRA_TEXT, texto);
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, "Share"));
    
04.07.2018 / 14:04
0

I think it's being cached, from my small experience, I think it depends on Android for Android, since I've seen some that only mark the last one used. My app has almost the same code that you posted, however with some minor modifications, but I've never particularly seen this problem that you mentioned. Following:

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
String msg = "Sua mensagem aqui"
shareIntent.putExtra(Intent.EXTRA_TEXT, msg);
startActivity(shareIntent);

If it does not resolve, then it probably should be your device, or rather the system of your device. See if when you first picked the app, whether it was added as sempre to the default settings, then go to the app settings you are launching and clear the defaults or defaults (something like that) and test your app on other devices and versions of Android.

I hope I have helped.

    
04.07.2018 / 02:49