0

there are few questions about this issue but none of them seems to help me, I have a dialog with a "Share in SMS" button. when I press it, I want to show the sms apps that can send it. it's working, but I get waaaaay more apps then I want. I want to only show the apps that are suppose to send sms, but it shows EVERYTHING.. linkedin, Facebook, gmail, basically every app.

i want only Messaging apps such as Messenger, and the default phone msg apps.

here's my current code :

Intent intent = new Intent(Intent.ACTION_SEND);
                    intent.setType("text/plain");
                    intent.putExtra(Intent.EXTRA_TEXT,
                            SharedPref.getNamePrefValue() +
                                    " shared " + doc.getName());
                    startActivity(intent);

how can I give only the apps i want in the list? I have tried "playing" with different setType options but none of them worked.

thanks a lot for helping!

JozeRi
  • 3,219
  • 6
  • 27
  • 45
  • Try this one http://stackoverflow.com/a/20079048/1020530 (there are 2 answers there, depends on your needs, also please note about the bug with Hangouts with all the solutions) – nheimann1 Feb 25 '15 at 11:28
  • Look here http://stackoverflow.com/questions/2372248/launch-sms-application-with-an-intent perfect solution for you – Josef Feb 25 '15 at 12:51

4 Answers4

0

This is how it works. You just lists all apps that declare ability to deal with text/plain content. I'd suggest to not limit your users and change label of your button from "Share with SMS" to just "Share" and let your users decide.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
0

You can create an intent for a specific app using its packagename, so your intent will be delivered to that specific app and no dialog will be displayed. But if the app is not installed you'll have to deal with it, maybe prompting users to go to the play store.

I recomend you to do what @marcin-orlowski recomends: narrow the posibilities with intent filter and let the user decide which application will handle data.

Juanjo Vega
  • 1,410
  • 1
  • 12
  • 20
0

To indicate that you want send a sms, just specify the intent data like this :

intent.setData(Uri.parse("sms:"));

Then the chooser will present you only apps that can deal with sms. Note that to specify the body of the sms, you can use :

intent.putExtra("sms_body", "the text to send"); 
ben75
  • 29,217
  • 10
  • 88
  • 134
  • 1
    this works with ACTION_VIEW but not ACTION_SEND, and in ACTION_VIEW the share doesn't well with some text apps, like google "Messenger" – JozeRi Feb 25 '15 at 12:37
0
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", SMS_BODY);
sendIntent.setType("vnd.android-dir/mms-sms");
activity.startActivity(sendIntent);

I hope this answer can help you

Amrut Bidri
  • 6,276
  • 6
  • 38
  • 80
  • in ACTION_VIEW the share doesn't well with some text apps, like google "Messenger" – JozeRi Feb 25 '15 at 12:37
  • 1
    based on your question, this answer is only for sending SMS not chat messages. you elaborate the question properly. thanx – Amrut Bidri Feb 25 '15 at 13:09