Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
373 views
in Technique[技术] by (71.8m points)

android - how to receive text sms to specific port..

How to receive text sms to a specific port? I have been looking for an answer to this question but to no avail. This has been asked a few times but nobody seems to have a clear answer. My code is as follows:

--MANIFEST FILE--

<receiver android:name=".SMSRecieve" android:enabled="true"> 
<intent-filter> 
<action android:name="android.intent.action.DATA_SMS_RECEIVED"/> 
<data android:scheme="sms" /> 
<data android:host="localhost" /> 
<data android:port="15005" /> 
</intent-filter> 
</receiver>

--SMS sending method--

String messageText = msgTxt.getText().toString(); 
short SMS_PORT = 15005; 
SmsManager smsManager = SmsManager.getDefault(); 
smsManager.sendDataMessage("5556", null, SMS_PORT, messageText.getBytes(), null, null); 

--Broadcast Receiver code--

static final String ACTION = "android.intent.action.DATA_SMS_RECEIVED"; 
//static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";(tried this too, but failed) 

if (intent.getAction().equals(SMSNotifyExample.ACTION)) { 
...do some work.. 
}

I also tried to replace android:name to android.provider.Telephony.SMS_RECEIVED but the result is the same.

My application does not receive the SMS on the specified port. Once I remove the following line it works fine:

<data android:scheme="sms" /> 
<data android:host="localhost" /> 
<data android:port="15005" /> 

Could you suggest what am I missing?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Thanks for the hint!

I use this and it works:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...