Alexis
Alexis

Reputation: 16829

How to send a message in android 2.2?

I want to send a message (sms/mms) with android 2.2. First I made an intent chooser with an ACTION_SEND to select which to use :

Intent intent = new Intent(Intent.ACTION_SEND);

intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, Resources.getString("InvitationSubject", getBaseContext()));
String body = Resources.getString("InvitationBody", getBaseContext()) + Local.User.FirstName;
intent.putExtra(Intent.EXTRA_TEXT, body);

startActivity(Intent.createChooser(intent, "Invite friends"));

But in that case, the selector show 'Bluetooth, Messaging, Google+, Gmail'. I want to show ONLY Messaging or other messaging apps.

I saw in the sdk docs there's a new CATEGORY_APP_MESSAGING to use but it's only available in the API level 15. I have to keep API level 8. Is there a way to do that ?

Upvotes: 1

Views: 600

Answers (3)

Ronak Mehta
Ronak Mehta

Reputation: 5979

use following code to send message

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "message subject");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "text");
startActivity(Intent.createChooser(shareIntent, "Pick a Share method"));

Gives following permission

<uses-permission android:name="android.permission.SEND_SMS" />

Upvotes: 0

Aerrow
Aerrow

Reputation: 12134

Try this code

String body = Resources.getString("InvitationBody", getBaseContext()) + Local.User.FirstName;
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", smsBody); 
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);

Don't forget to add this <uses-permission android:name="android.permission.SEND_SMS" /> in your manifest.

Upvotes: 2

Rawkode
Rawkode

Reputation: 22592

You can use the type mms-sms, like so

intent.setType("vnd.android-dir/mms-sms");

Upvotes: 0

Related Questions