Wednesday, February 29, 2012

android: receive sms from different port

to receive sms from a different port, set this receiver in your AndroidManifest.xml

<receiver android:name=".SMSBcastReceiver">
        <intent-filter android:priority="10"> 
        <action android:name="android.intent.action.DATA_SMS_RECEIVED" /> 
<data android:scheme="sms" /> 
            <data android:port="13013" /> 
</intent-filter>
</receiver>


then set this in your SMSBcastReceiver class

public void onReceive(final Context context, Intent intent) {

Bundle bundle = intent.getExtras();

Object messages[] = (Object[]) bundle.get("pdus");
SmsMessage smsMessage[] = new SmsMessage[messages.length];

for (int n = 0; n < messages.length; n++) 
{
smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
}

smsOrigin = smsMessage[0].getDisplayOriginatingAddress();
smsData = smsMessage[0].getUserData();

for(int index=0; index<smsData.length; ++index)
{
smsBody += Character.toString((char)smsData[index]);
}
}

that's it, pansit!

3 comments:

  1. hi linus
    my manifest file is:
    -----------------------------------







    ------------------------------
    but my demoApp dont receive any sms.
    please guide me.
    thanx

    ReplyDelete
  2. hi again
    excuse me,I do not know why the my code did not show up .
    i use your code you mentioned.
    What permissions do you have set؟

    ReplyDelete
  3. hi s.pahlavan, if you're receiving sms through a different port, you won't see it in your inbox like an ordinary sms. i use a toast in the onReceive() function to display what i receive.

    i have the following permisions set:




    i believe you only need RECEIVE_SMS for this.

    ReplyDelete

SSH : No matching host key type found. Their offer: ssh-rsa,ssh-dss

Got this while connecting to my mikrotik router via ssh   Unable to negotiate with <ip address> port <ssh port>: no matching hos...