how can I register my application so that when I receive a sms my app appears in dialog Complete action using. I have put in an intent code
<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"/>
</intent-filter>
but it's not working... should I use receiver? Note that the activity in which I've inserted this code is not main activity. Thanks
Use the following code.
<activity android:name=".SMSNewActivity" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android-dir/mms-sms" />
</intent-filter>
<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>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<activity android:name=".SMSMainListActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Its not well documented in doc.
You can find info on AndDev
Here are some extracts:
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<receiver android:name=".SMSReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
android.content.IntentReceiver
and override the onReceiveIntent method of the class listen for action android.provider.Telephony.SMS_RECEIVED
not part of SDKHere's some more code extract:
// @Override
public void onReceiveIntent(Context context, Intent intent) {
if (intent.getAction().equals(ACTION)) {
// if(message starts with SMStretcher recognize BYTE)
StringBuilder sb = new StringBuilder();
/* The SMS-Messages are 'hiding' within the extras of the Intent. */
Bundle bundle = intent.getExtras();
if (bundle != null) {
/* Get all messages contained in the Intent*/
SmsMessage[] messages =
Telephony.Sms.Intents.getMessagesFromIntent(intent);
/* Feed the StringBuilder with all Messages found. */
for (SmsMessage currentMessage: messages) {
sb.append("Received compressed SMSnFrom: ");
/* Sender-Number */
sb.append(currentMessage.getDisplayOriginatingAddress());
sb.append("n----Message----n");
/* Actual Message-Content */
sb.append(currentMessage.getDisplayMessageBody());
}
}
/* Logger Debug-Output */
Log.i(LOG_TAG, "[SMSApp] onReceiveIntent: " + sb);
/* Show the Notification containing the Message. */
Toast.makeText(context, sb.toString(), Toast.LENGTH_LONG).show();
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