Android的 - 创建一个从PDU德precated API的短信? [英] Android - Create SMS from PDU deprecated API?

查看:147
本文介绍了Android的 - 创建一个从PDU德precated API的短信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个应用程序,得到通知时,短信到达并处理短信,但阅读的参考<一个href=\"http://developer.android.com/reference/android/telephony/SmsMessage.html#createFromPdu%28byte%5B%5D%29\">createFromPdu功能,它指出:

I want to create an app that gets notified when an SMS arrives and processes that SMS, but reading the reference for the createFromPdu function, it states that:

这个方法很快就会去precated并通过处理SMS_RECEIVED_ACTION广播意图处理收到的短消息的所有应用程序现在必须从意图通过新的格式字符串附加到新的方法createFromPdu(字节[],字符串)这需要一个额外的格式参数。这是必需的,以便正确地德code中的PDU上,需要对3GPP和3GPP2格式的同时,如双模式GSM / CDMA和CDMA / LTE电话支持设备

This method will soon be deprecated and all applications which handle incoming SMS messages by processing the SMS_RECEIVED_ACTION broadcast intent must now pass the new format String extra from the intent into the new method createFromPdu(byte[], String) which takes an extra format parameter. This is required in order to correctly decode the PDU on devices that require support for both 3GPP and 3GPP2 formats at the same time, such as dual-mode GSM/CDMA and CDMA/LTE phones.

然而, createFromPdu(字节[],字符串)功能同时从文档和SDK缺少的。

However the createFromPdu(byte[], String) function is missing from both the documentation and the SDK.

我应该怎么办?我需要支持这些双卡双模手机。

What should I do? I need to support these dual-sim dual-mode phones.

推荐答案

在短,使用:

SmsMessage smsMessage;

if (Build.VERSION.SDK_INT >= 19) { //KITKAT         
    SmsMessage[] msgs = Telephony.Sms.Intents.getMessagesFromIntent(intent);              
    smsMessage = msgs[0];            
} else {             
    Object pdus[] = (Object[]) bundle.get("pdus");             
    smsMessage = SmsMessage.createFromPdu((byte[]) pdus[0]);          
}

这篇关于Android的 - 创建一个从PDU德precated API的短信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆