Wrox Programmer Forums
BOOK: Professional Android 4 Application Development
This is the forum to discuss the Wrox book Professional Android 4 Application Development Reto Meier; ISBN: 978-1-1181-0227-5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Android 4 Application Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old May 17th, 2012, 10:05 PM
Registered User
Join Date: May 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with MySMSReceiver


I just bought the book and it is really helpful. I am trying to get a simple program to just receive SMS Texts. I've used the example in your book on page 718 and when I run the code below I get the error "Unfortunately, SMSReceiver has stopped".

Am I missing something?

Can you help? I just want to be able to receive SMS message.



public class SMSReceiverActivity extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {

public class MySMSReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++)
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);

for (SmsMessage message: messages) {
String msg = message.getMessageBody();
long when = message.getTimestampMillis();
String from = message.getOriginatingAddress();

Toast.makeText(context, from + " : " + msg,



Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.