Reputation: 1104
I have tried to use the sendDataMessage() of android.telephony.SmsManager with the help of almost every sample that i could come accross.. Yet no success..
[In case u want to see the code then simply check the "Sending Sms android" link on mobiForge, i guess its the most popular one (and the one that i've used).]
This is one of the examples in reference to this question.
When i use the standard receiver shown in samples as follows, my Broadcast Receiver does indeed get activated and i am able to see the Toast which contains my message thus proving that my receiver is successfully running. [By the way, i am calling the SmsManager.sendTextMessage() which is working successfully so no issues there].
<receiver android:name=".SMSReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
However when i use the following receiver, i am unable to get the Toast which means that my receiver is clearly not getting activated, hence no Toast.
<receiver android:name=".SMSReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<data android:port="8901"/>
<data android:scheme="sms"/>
</intent-filter>
</receiver>
My question here is Why? In case some of you are thinking that the port number in my sendDataMessage() is not right then i assure you that its 8901 which is a short value.
Hence i would like to request anyone with a solution to this to either explain the solution or provide a working example.
Thanking anyone who can help in advance!
Best Regards, Siddhant
Upvotes: 2
Views: 6393
Reputation: 1104
Well i seem to have found out the problem in my code.
The fix was to change the android:name value in the above shown receiver from android.provider.Telephony.SMS_RECEIVED to android.intent.action.DATA_SMS_RECEIVED
So the new receiver will look like:
<receiver android:name=".SMSReceiver">
<intent-filter>
<action android:name="android.intent.action.DATA_SMS_RECEIVED" />
<data android:port="8901"/>
<data android:scheme="sms"/>
</intent-filter>
</receiver>
Thanks to KRVarma SMSDemo which provided some really useful insight after understanding the code.
Upvotes: 2
Reputation: 2075
Here are details of a possible bug with the Android emulator regarding this functionality.
Upvotes: 0