Java 在Android中创建CDMA(3gpp2)PDU
上周我问了一个类似的问题,甚至还悬赏了它,因为我意识到这个问题的答案是a的,并且它在模拟器(android 2.2)中运行得非常完美。我接受了答案并颁发了奖金,并更改了头衔以备将来参考 问题: 现在,我在问如何创建一个CDMA(3gpp2)PDU,类似于创建一个可以在Android的APIJava 在Android中创建CDMA(3gpp2)PDU,java,android,cdma,pdu,Java,Android,Cdma,Pdu,上周我问了一个类似的问题,甚至还悬赏了它,因为我意识到这个问题的答案是a的,并且它在模拟器(android 2.2)中运行得非常完美。我接受了答案并颁发了奖金,并更改了头衔以备将来参考 问题: 现在,我在问如何创建一个CDMA(3gpp2)PDU,类似于创建一个可以在Android的APIcreateFromPdu() 尽量避免自己写: 读到新方法时我很兴奋 然后意识到这是不向后兼容的 我甚至对使用com.android.internal.telephony.gsm.SmsMessage.cre
createFromPdu()
尽量避免自己写:
读到新方法时我很兴奋
然后意识到这是不向后兼容的
我甚至对使用com.android.internal.telephony.gsm.SmsMessage.createFromPdu(pdu)感到好奇代码>使用从生成的GSM PDU。但我不确定那是否安全
所以我决定最好的方法是根据设备类型创建GSM或CDMA PDU
有没有人有可以创建CDMA PDU的代码片段
或者知道如何将创建GSM PDU的方法转换为CDMA PDU格式
更新:
我一直在努力手动创建一种方法来创建CDMA(3gpp2)pdu
我已经接近成功了
但我似乎不明白如何正确地将BearerData
和cat日期字符串打包到pdu的末尾,这就是我目前所掌握的
private static byte[] createCDMAPDU(String sender, String body) {
byte[] pdu = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream(100);
DataOutputStream dos = new DataOutputStream(baos);
Date now = new Date ();
byte[] dateBytes = new byte[6];
Calendar calendar = new GregorianCalendar();
dateBytes[0] = (byte) (asBytes(""+calendar.get(Calendar.YEAR))[0]);
dateBytes[1] = (byte) (asBytes(""+calendar.get(Calendar.MONTH) + 1)[0]);
dateBytes[2] = (byte) (asBytes(""+calendar.get(Calendar.DAY_OF_MONTH))[0]);
dateBytes[3] = (byte) (asBytes(""+calendar.get(Calendar.HOUR_OF_DAY))[0]);
dateBytes[4] = (byte) (asBytes(""+calendar.get(Calendar.MINUTE))[0]);
dateBytes[5] = (byte) (asBytes(""+calendar.get(Calendar.SECOND))[0]);
try {
dos.write(0);// unknown padding
dos.write(0);// unknown padding
dos.write(0);// unknown padding
// MESSAGE_TYPE_POINT_TO_POINT = 0x00;
// MESSAGE_TYPE_BROADCAST = 0x01;
// MESSAGE_TYPE_ACKNOWLEDGE = 0x02;
dos.write(0x00);// message type - MESSAGE_TYPE_POINT_TO_POINT
// TELESERVICE_NOT_SET = 0x0000;
// TELESERVICE_WMT = 0x1002;
// TELESERVICE_VMN = 0x1003;
// TELESERVICE_WAP = 0x1004;
// TELESERVICE_WEMT = 0x1005;
dos.writeInt(0x1002); // teleservice - TELESERVICE_NOT_SET
// dos.writeInt(0); // servicePresent
dos.writeInt(0); // serviceCategory
// DIGIT_MODE_4BIT_DTMF = 0x00;
// DIGIT_MODE_8BIT_CHAR = 0x01;
dos.write(0x01);// digit mode - DIGIT_MODE_4BIT_DTMF
// NUMBER_MODE_NOT_DATA_NETWORK = 0x00;
// NUMBER_MODE_DATA_NETWORK = 0x01;
dos.write(0x00);// number mode - NUMBER_MODE_NOT_DATA_NETWORK
// TON_UNKNOWN = 0x00;
// TON_INTERNATIONAL_OR_IP = 0x01;
// TON_NATIONAL_OR_EMAIL = 0x02;
// TON_NETWORK = 0x03;
// TON_SUBSCRIBER = 0x04;
// TON_ALPHANUMERIC = 0x05;
// TON_ABBREVIATED = 0x06;
// TON_RESERVED = 0x07;
dos.write(0x00); // number_type - TON_UNKNOWN
// NUMBERING_PLAN_UNKNOWN = 0x0;
// NUMBERING_PLAN_ISDN_TELEPHONY = 0x1;
dos.write(0x0);// number plan - NUMBERING_PLAN_UNKNOWN
dos.write(sender.length());// number of digits
dos.write(sender.getBytes(), 0, sender.getBytes().length); // digits
dos.write(0);// bearer reply ?
dos.write(0);// bearer reply ?
// Subaddress is not supported.
dos.write(0); // subaddressType
dos.write(0); // subaddr_odd
dos.write(0); // subaddr_nbr_of_digits
// dos.write(encodedBearerData.length);
// dos.write(encodedBearerData, 0, encodedBearerData.length);
dos.write(0);
dos.write(0);
dos.write(0);
dos.write(0);
dos.write(0);
byte[] bodybytes = getAsciiBytes(body);
dos.write(bodybytes.length);
dos.write(0);
dos.write(0x03);
dos.write(0x10);
dos.write(0);
dos.write(bodybytes, 0, bodybytes.length);
dos.write(0);
dos.write(dateBytes.length);
dos.write(dateBytes);
dos.close();
pdu = baos.toByteArray();
} catch (IOException e) {
}
return pdu;
}
我不确定我是否在正确的轨道上。嗨,我们又见面了。您可以尝试使用reflection
来获取此方法<代码>菜单开发
从中创建。最后他们mention@Yul你有没有可能增加我的进度,手动创建它?(我甚至不完全确定自己是否走上了正确的道路)但我想我应该尽量避免反思。除非你能用反射来完成,否则我也会接受。我已经有一段时间没有使用Android了。如果我发现有趣的东西,我会添加答案:)。