600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > android发送数据短信 如何发送和接收数据短信

android发送数据短信 如何发送和接收数据短信

时间:2019-11-02 11:52:46

相关推荐

android发送数据短信 如何发送和接收数据短信

我知道我在回复时只有1岁,但我认为它仍然可以帮助某人。

接收:

Bundle bundle = intent.getExtras();

String recMsgString = "";

String fromAddress = "";

SmsMessage recMsg = null;

byte[] data = null;

if (bundle != null)

{

//---retrieve the SMS message received---

Object[] pdus = (Object[]) bundle.get("pdus");

for (int i=0; i

recMsg = SmsMessage.createFromPdu((byte[])pdus[i]);

try {

data = recMsg.getUserData();

} catch (Exception e){

}

if (data!=null){

for(int index=0; index

{

recMsgString += Character.toString((char)data[index]);

}

}

fromAddress = recMsg.getOriginatingAddress();

}

在清单中设置接收器:

正在发送:

String messageText = "message!";

short SMS_PORT = 8901; //you can use a different port if you'd like. I believe it just has to be an int value.

SmsManager smsManager = SmsManager.getDefault();

smsManager.sendDataMessage("8675309", null, SMS_PORT, messageText.getBytes(), null, null);

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。