I tried this code in my android application for the SMS message but it is not working , the application does not appear in the messaging list. Should I add something to make it work?
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
<data android:mimeType="text/plain" />
</intent-filter>
An intent filter is an expression in an app's manifest file that specifies the type of intents that the component would like to receive. For instance, by declaring an intent filter for an activity, you make it possible for other apps to directly start your activity with a certain kind of intent.
An intent is an object that can hold the os or other app activity and its data in uri form.It is started using startActivity(intent-obj).. \n whereas IntentFilter can fetch activity information on os or other app activities.
The intent filter specifies the types of intents that an activity, service, or broadcast receiver can respond. Intent filters are declared in the Android manifest file. Intent filter must contain <action>
The Intent Resolution compares the contents of Intent Object against the Intent Filters. (Intent Filters are associated with the different Android components, and can receive Intent. Intent filter is a way for Android components to declare their capabilities to the Android system.)
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With