SmsManager.sendDataMessage(…, onSpecificPort , …,.. ) Is not Filtering SMS On Port Basis

本小妞迷上赌 提交于 2019-12-12 03:16:16

问题


What i want to do is

Send SMS on a specific PORT and application listening to sms receiving for the same port should only react to the sms receiving.

I have a receiver like this

    <receiver android:name=".BinarySMSReceiver"> 
        <intent-filter> 
            <action android:name="android.intent.action.DATA_SMS_RECEIVED"/>
            <data android:port="8091"/>
            <data android:scheme="sms"/> 
        </intent-filter> 
    </receiver>

and sending sms like below

manager.sendDataMessage(phonenumber, null, (short) SMS_PORT, data, piSend, piDelivered);

MyReceiver did receive the msg but issue along side others receivers are also able to listen.

My native inbox of device is also catching the sms.

If i declare another receiver with different port number they are also able to listen. verified with my logs.

or if i change port number for my first receiver even then it receives .

Only god know why this port is not filtering sms.

Please gave suggestions. Any direction or hint or solution are welcomed.

Thanks


回答1:


Answer is that this port filtering doesn't work well for all the devices of different manufacturers.

Workaround is

Try sending simple text messages. With in the message body add some of your own header information to let your receiver know that it is your sms.

Like

messageBody = "//someHeaderPattern:" + messageBody;

make your receiver listening priority very high.

If your receiver detect its your sms. abortBroadcast to avoid other listen the same. else do nothing.

This is just a workaround nothing is guaranteed



来源:https://stackoverflow.com/questions/9616261/smsmanager-senddatamessage-onspecificport-is-not-filtering-sms-o

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!