本文介绍了创建针对Android PDU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在写和应用,正在发送/接收短信。

I am currently writing and application, that is sending/receiving SMS messages.

有关单元测试目的,我需要以编程方式创建PDU。解码是很容易的:

For unit-testing purposes I need to create PDU programmatically. Decoding is quite easy:

Bundle bundle = intent.getExtras();
if (bundle != null) {
    /* Get all messages contained in the Intent*/
    Object[] pdusObj = (Object[]) bundle.get("pdus");
    for (int i = 0; i < pdusObj.length; i++) {
        SmsMessage msg = SmsMessage.createFromPdu((byte[])pdusObj[i]);
    }
}

有没有为创建 PDU programamtically任何适当的方式?

Is there any appropriate way to create PDU programamtically?

推荐答案

典型的PDU都在code硬codeD。与此类似:

Typically PDUs are hardcoded in the code. Similar to this:

String pdu = "07914151551512f2040B916105551511f100006060605130308A04D4F29C0E";
SmsMessage sms = SmsMessage.createFromPdu(HexDump.hexStringToByteArray(pdu));

这里是如何做到这一个完整的例子。

Here's a complete example on how to do this.

现在,你会问我,我在哪里可以找到用于测试的PDU?你生成它。例如,您可以使用在线服务。

Now, you're gonna ask me "where can I find a PDU for testing?" You generate it. For example, you can use this online service.

我希望这有助于!

这篇关于创建针对Android PDU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 10:36