我无法找到这个问题的答案。为什么从一个仿真器实例以编程方式发送到另一个仿真器实例的数据SMS的长度在接收端被截断? 这里我从 emulator-554 发送20个字节到 emulator-556 ,但是 emulator-556 只接收 12个字节:
<小时/> 模拟器-554:短信发送者
/** Send data SMS between two emulators from 15555215554 to 15555215556. */
private void sendSMS()
{
final int udLength = 20; // SMS user data length in bytes
Log.d("SMS TEST", "SMSActivity.sendSMS ud.length=" + udLength);
byte[] payload = new byte[udLength];
for (byte i = 0; i < udLength; i++)
{
Log.d("SMS TEST", "payload[" + i + "]=" + i);
payload[i] = i;
}
Intent smsSentIntent = new Intent("SMS_SENT");
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, smsSentIntent, 0);
String destTelephone = "15555215556";
SmsManager smsMgr = SmsManager.getDefault();
smsMgr.sendDataMessage(destTelephone, null, (short) 32766, payload, sentPI, null);
Log.d("SMS TEST", "SMSActivity.sendSMS COMPLETED!");
}
登录发件人模拟器:
02-25 19:31:00.793:D / SMS TEST(257):onCreate
02-25 19:31:00.793:D / SMS TEST(257):onResume
02-25 19:31:00.823:D / SMS TEST(257):SMSActivity.sendSMS ud.length = 20
02-25 19:31:00.823:D / SMS TEST(257):payload [0] = 0
02-25 19:31:00.823:D / SMS TEST(257):有效载荷[1] = 1
02-25 19:31:00.823:D / SMS TEST(257):有效载荷[2] = 2
02-25 19:31:00.823:D / SMS TEST(257):有效载荷[3] = 3
02-25 19:31:00.823:D / SMS TEST(257):payload [4] = 4
02-25 19:31:00.823:D / SMS TEST(257):payload [5] = 5
02-25 19:31:00.823:D / SMS TEST(257):有效载荷[6] = 6
02-25 19:31:00.823:D / SMS TEST(257):有效载荷[7] = 7
02-25 19:31:00.833:D / SMS TEST(257):payload [8] = 8
02-25 19:31:00.833:D / SMS TEST(257):payload [9] = 9
02-25 19:31:00.833:D / SMS TEST(257):有效载荷[10] = 10
02-25 19:31:00.833:D / SMS TEST(257):payload [11] = 11
02-25 19:31:00.833:D / SMS TEST(257):有效载荷[12] = 12
02-25 19:31:00.833:D / SMS TEST(257):有效载荷[13] = 13
02-25 19:31:00.833:D / SMS TEST(257):payload [14] = 14
02-25 19:31:00.833:D / SMS TEST(257):有效载荷[15] = 15
02-25 19:31:00.833:D / SMS TEST(257):有效载荷[16] = 16
02-25 19:31:00.833:D / SMS TEST(257):有效载荷[17] = 17
02-25 19:31:00.853:D / SMS TEST(257):有效载荷[18] = 18
02-25 19:31:00.853:D / SMS TEST(257):有效载荷[19] = 19
02-25 19:31:00.904:D / SMS TEST(257):SMSActivity.sendSMS已完成!
02-25 19:31:27.044:D / SMS TEST(257):onPause
02-25 19:31:27.583:D / SMS TEST(257):onStop
public class SmsReceiver extends BroadcastReceiver
{
/** BroadcastReceiver listener. */
@Override
public void onReceive(Context context, Intent intent)
{
if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED"))
{
Bundle bundle = intent.getExtras();
Object[] pdus = (Object[]) bundle.get("pdus");
Log.d("SMS TEST", "SmsReceiver.onReceive: pdus.length=" + pdus.length);
SmsMessage inboundSMS = SmsMessage.createFromPdu((byte[]) pdus[0]); // pdus.length==1
byte[] ud = inboundSMS.getUserData();
int udLength = ud.length;
Log.d("SMS TEST", "SmsReceiver.onReceive: ud.length=" + udLength);
for (int i = 0; i < udLength; i++)
{
Log.d("SMS TEST", "ud[" + i + "]=" + ud[i]);
}
Log.d("SMS TEST", "SmsReceiver.onReceive COMPLETED!");
}
}
}
登录接收模拟器:
02-25 19:31:01.593:D / SMS TEST(258):SmsReceiver.onReceive:pdus.length = 1
02-25 19:31:01.613:D / SMS TEST(258):SmsReceiver.onReceive:ud.length = 12
02-25 19:31:01.613:D / SMS TEST(258):ud [0] = 0
02-25 19:31:01.613:D / SMS TEST(258):ud [1] = 1
02-25 19:31:01.613:D / SMS TEST(258):ud [2] = 2
02-25 19:31:01.613:D / SMS TEST(258):ud [3] = 3
02-25 19:31:01.613:D / SMS TEST(258):ud [4] = 4
02-25 19:31:01.613:D / SMS TEST(258):ud [5] = 5
02-25 19:31:01.613:D / SMS TEST(258):ud [6] = 6
02-25 19:31:01.613:D / SMS TEST(258):ud [7] = 7
02-25 19:31:01.613:D / SMS TEST(258):ud [8] = 8
02-25 19:31:01.613:D / SMS TEST(258):ud [9] = 9
02-25 19:31:01.623:D / SMS TEST(258):ud [10] = 10
02-25 19:31:01.623:D / SMS TEST(258):ud [11] = 3
02-25 19:31:01.623:D / SMS TEST(258):SmsReceiver.onReceive已完成!
Data=home, Speed=Full, Latency=None
使用:Android Development Toolkit 16.0.1.v201112150204-238534
Android 2.2 (API level 8)
Eclipse SDK 3.6.2
这是一个模拟器问题吗?其他人可以复制这种行为吗?我一直坚持这个问题太久了。任何帮助都会非常感激!
答案 0 :(得分:0)
它可能与端口号有关。尝试使用小于256的端口号。