Search code examples
androidsmsbroadcastreceiverandroid-manifestintentfilter

receive sms sent to a particular port


It is a recurrent question but I wasn't able to find a complete enough documentation on this topic.

I already have a working application able to intercept SMS, when it is send with default parameter with kannel or other device. My manifest look like this :

<receiver
    android:name=".sms.SMSListener"
    android:enabled="true" >
    <intent-filter>
        <action android:name="android.provider.Telephony.SMS_RECEIVED" />    
    </intent-filter>
</receiver>

It works both with android.provider.Telephony.SMS_RECEIVED and android.intent.action.DATA_SMS_RECEIVED.

But for the purpose of my application, the SMS must not appear in the user-inbox. For that, kannel sent the SMS to a specific port. It is already working on Blackberry, so I guess the sending part of the problem is already working. Also it may be possible to achieve this goal via other means, I need to implement this solution in order to stay coherent with other similar project. Another reason for that, is to avoid my BroadcastReceiver to be fired at each received SMS (and thus needing to parse each received SMS).

However with my current manifest, I don't receive SMS sent to a specific port (my receiver isn't fired at all). After some research, I found those topic how to receive text sms to specific port.., How to send and receive data SMS messages. Someone say that adding :

<data android:scheme="sms" />
<data android:port="1234" />

is enough to work (unfortunately, it doesn't works for me). However according to the documentation ( http://developer.android.com/guide/topics/manifest/data-element.html ) you need to specify the android:scheme then the android:host in order for android:port to be taken into account. As far as I understand the documentation, you could just specify android:scheme and the intent-filter should still be functionnal. However as soon as I specify the android:scheme, my BroadcastReceiver cease to work, whether or not I send the sms with a specific port :

<receiver
    android:name=".sms.SMSListener"
    android:enabled="true" >
    <intent-filter>
        <action android:name="android.provider.Telephony.SMS_RECEIVED" />    
        <data android:scheme="sms" />
    </intent-filter>
</receiver>

So my questions are the following:

  1. is there somewhere a documention about which value android:scheme can take ?
  2. which value should I use for android:host ?
  3. is there somewhere an app which listen SMS to every port so I can be sure that the test SMS is correctly sent (just to double check this part) ?

Solution

  • I finally manage to understand what was wrong :

    I was sending my data sms to the port 2948 which is reserved for WAP-PUSH message. So android do not broadcast those message to my android.intent.action.DATA_SMS_RECEIVED receiver. Using a different port solved the issue.

    Moreover, android seems to have problems with 8 bits encoded SMS (at least it rise a warning in the logs.). However my main problem is solved.