简体   繁体   中英

Telephony class error

I am learning from a tutorial, and the following code doesn't work:

SmsMessage msg[] = Telephony.Sms.Intents.getMessagesFromIntent(intent);

I think it is no more part of the framework, but I haven't found what to use instead.

How can I get the sms message? (this is in the onReceive method of a BroadcastReceiver)

I found a solution :)

Bundle bundle = intent.getExtras();
    SmsMessage[] msgs = null;
    String str = "";
    if (bundle != null) {
        // ---retrieve the SMS message received---
        Object[] pdus = (Object[]) bundle.get("pdus");
        msgs = new SmsMessage[pdus.length];
        for (int i = 0; i < msgs.length; i++) {
            msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);

            str += msgs[i].getMessageBody().toString();

        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM