Problem with sharing

Asked

Viewed 26 times

0

I used the following code to capture a 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 first ran it it opened properly the share containing all the applications. When I run it again it goes straight to the application I chose the first time. It’s like I’m saved. But I want it to always open the share to choose from. How to solve this ?

2 answers

2

To solve 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 has been 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"));

0

I believe it is being cached, for my little experience, I believe that it depends on Android for Android, because I’ve seen some that only mark the last used. My app has almost the same code you posted, however with some minor modifications, but that particularly never occurred this problem you mentioned. Follows:

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 doesn’t, then it’s probably your device, or rather your device’s system. See if when you first selected the app, if you added it as sempre in the presets, then go to the settings of the app that is starting and clear the presets or patterns (something of the type) and test your app on other devices and versions of Android.

I hope I’ve helped.

  • Unfortunately not solved. It still keeps opening the same app instead of opening the sharing options.

  • I will reply with a few more considerations

Browser other questions tagged

You are not signed in. Login or sign up in order to post.