I am providing you a detailed desc to do that in different case(with contacts, text shares etc).
Manifest Entry for you Message Activity
<!-- Defines also the app name in the Android menu -->
<activity
android:name="it.rainbowbreeze.smsforfree.ui.ActSendSms"
android:label="@string/common_appName"
>
<!-- Sends sms for someone -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
</intent-filter>
<!-- Sends text to someone .This will enable any Text Share functionality-->
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
Now we have made a processIntentData method as shown below to be applied in Message Activity:
private void processIntentData(Intent intent)
{
if (null == intent) return;
if (Intent.ACTION_SENDTO.equals(intent.getAction())) {
//in the data i'll find the number of the destination
String destionationNumber = intent.getDataString();
destionationNumber = URLDecoder.decode(destionationNumber);
//clear the string
destionationNumber = destionationNumber.replace("-", "")
.replace("smsto:", "")
.replace("sms:", "");
//and set fields
mTxtDestination.setText(destionationNumber);
} else if (Intent.ACTION_SEND.equals(intent.getAction()) && "text/plain".equals(intent.getType())) {
//in the data i'll find the content of the message
String message = intent.getStringExtra(Intent.EXTRA_TEXT);
//clear the string
mTxtBody.setText(message);
}
}
Use as shown in Message Activity:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
mTxtDestination = (EditText) findViewById(R.id.actsendsms_txtDestination);
mTxtBody = (EditText) findViewById(R.id.actsendsms_txtMessage);
...
//executed when the application first runs
if (null == savedInstanceState) {
processIntentData(getIntent());
}
}
The attached snap for results: