3

I was messing around with the Android SDK, and noticed that in one of the examples for receiving SMS messages, the execution of onReceive never got past Intent.getExtras(). I added Logs before and after that line to be sure, and no logs after getExtras are executed. Android emulator version is 4.0.3. Can anyone point out some flaw in this code that I'm not seeing, or offer a workaround or solution to this seemingly random and frustrating issue?

public class SmsReceiver extends BroadcastReceiver 
{
    @Override
    public void onReceive(Context context, Intent intent) 
    {
        Log.i("smsreceiver", "Intent: " + intent.getAction()); //Shows up in LogCat normally
        Bundle bundle = intent.getExtras();
        Log.i("smsreceiver", "after"); //this is never reached, and nothing after this is executed

        Object messages[] = (Object[]) bundle.get("pdus");
        SmsMessage smsMessage[] = new SmsMessage[messages.length];
        for (int n = 0; n < messages.length; n++) 
        {
            smsMessage[n] = SmsMessage.createFromPdu((byte[])messages[n]);

        }
        Log.i("smsreceiver", "Message: " + smsMessage[0].getMessageBody());

    }
}

1 Answers1

0

I would run your application under a debugger, and get it to "hang" like you mentioned, and then manually break into the application, and see where execution is at. This may give you a hint of what might be the cause.

For bonus points, you could set up your IDE to be able to resolve the framework source code, and then actually debug into the getExtras() call, to figure out what is going wrong.

JesusFreke
  • 19,784
  • 5
  • 65
  • 68