Argh. Disregard. Somehow the emulator being run was still using the 1.5 SDK. Seems to work fine on the 1.6 SDK. Sorry about that.
On Sep 17, 4:46 am, King of Camelot <[email protected]> wrote: > So I was playing around with some sample code I found on the net for > receiving SMS in your app when I noticed that the sample was using the > deprecated android.telephony.gsm.SmsMessage. I figured it'd be a > simple change to make it use android.telephony.SmsMessage instead so I > changed the import and everything compiled just fine. > > However, when I ran the app, it crashed when an SMS was received. > After playing around with it for quite a while I can not seem to > figure out why it doesn't work with the changed import. > > Here's the code in question (not my code, it was in a sample online, > but I don't have the URL): > > public void onReceive(Context context, Intent intent) { > Bundle bundle = intent.getExtras(); > > 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]); > } > > // show first message > Toast toast = Toast.makeText(context, > "Received SMS:" + smsMessage[0].getDisplayOriginatingAddress > (), Toast.LENGTH_LONG); > toast.show(); > } > > One bit I did notice was that the non-deprecated SmsMessage class does > not have a public constructor, which seemed to give the creation of > the SmsMessage array some problems. However, even after removing > everything except the SmsMessage.createFromPdu line the app was still > crashing. > > Does anyone have any insight into what's different between the two > SmsMessage classes that is causing this? > > Thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---

