sendDataMessage()针对Android的工作示例 [英] Working example of sendDataMessage() for android
问题描述
我曾尝试使用 sendDataMessage()的 android.telephony.SmsManager 几乎每个样本的帮助下,我可以翻过来..但没有成功。
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..
[如果ü要看到code,则只需选中发送短信机器人关于mobiForge链接,我想它的一个最流行的(而且我用的)。]
[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.
当我使用的样本所示的标准接收如下,我的广播接收器确实得到激活,我能看到它包含我的消息,由此证明我的接收器成功运行的吐司。 [顺便说一句,我打电话在 SmsManager.sendTextMessage()这是成功的工作,所以没有任何问题。
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>
我在这里的问题是,为什么?
在某些情况下,你在想,在我的sendDataMessage()的端口号是不正确的话,我向你保证,其8901这是一个短值。
因此,我想用一个解决的办法,要求任何人要么说明溶液或提供工作的例子。
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!
最好的问候,
Siddhant
Best Regards, Siddhant
推荐答案
嗯,我似乎在我的code已经发现了这个问题。
Well i seem to have found out the problem in my code.
此修复程序是更改的android:名称在如上图所示,从接收的 android.provider.Telephony.SMS_RECEIVED 为 android.intent.action值。 DATA_SMS_RECEIVED
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>
感谢 KRVarma SMSDemo 它理解code之后提供一些真正有用的见解。
Thanks to KRVarma SMSDemo which provided some really useful insight after understanding the code.
这篇关于sendDataMessage()针对Android的工作示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!