Android - 从 PDU 已弃用的 API 创建 SMS?

标签 android sms deprecated android-6.0-marshmallow

我想创建一个应用程序,当 SMS 到达并处理该 SMS 时收到通知,但阅读 createFromPdu 的引用函数,它指出:

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.

但是,文档和 SDK 中都缺少 createFromPdu(byte[], String) 函数。

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

最佳答案

简而言之,使用这个:

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 已弃用的 API 创建 SMS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18876274/

相关文章:

php -/e 修饰符已弃用,从 php5.2.6 迁移后改用 preg_replace_callback

android - openFileChooser Android 4.4.4 缺少文件名

android - 使用gradle构建android项目时,lateinit属性variantName尚未初始化错误

Android 从模拟器测试短信

iphone - 使用什么来代替已弃用的 UIImagePickerControllerDelegate 方法?

android - WifiManager startScan已弃用。另类?

android - 我在哪里找到由 android 应用程序修改的文件

java - Dagger 2 : error while getting a multiple instances of same object with @Named

android - 我无法从 Android 的 Kitkat 版本的收件箱中删除短信

Android 5.0.2 - 短信广播接收器 - 无法正常工作