Why I couldn't retrieve the phone number from intent in onReceive of BroadcastReceiver

by gganesh » Thu, 10 Sep 2009 13:22:56 GMT

Sponsored Links
This is a simple application which sends  group  sms (a group consist
only 5 phone numbers )and i have registered  a Broadcast to announce
as sms is send .here i need to display the number to which the
sms is send ,how to do that
here is my code
# In onCreate()

 button is pressed it triggers  an onClick event and sends the group
public void onClick()
      for (int j = 0; j<phonenos.length;j++)
 String SENT = "SMS_SENT";
 private void sendSMS(String phoneNumber, String message)

     Intent ss=new Intent(SENT);
    ss.putExtra("phno1", phoneNumber); //*****I added this line so
that later i can retrieve the ph no
     PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,ss,0);
     SmsManager sms = SmsManager.getDefault();
     sms.sendTextMessage(phoneNumber, null, message, sentPI, null);

public void onStart()
       br_send=new BroadcastReceiver(){
           public void onReceive(Context arg0, Intent arg1) {
               switch (getResultCode())
                   case Activity.RESULT_OK:
                      Toast.makeText(getBaseContext(), "SMS
sent",                              Toast.LENGTH_SHORT).show();

                       Log.v(TAGS,"intent  :"+arg1.getExtras
().getString("phon1")); //*****error *****

       registerReceiver(br_send,new IntentFilter(SENT));

 public void onStop()
an error is thrown at arg1.getExtras().getString("phon1") Log
statement  ,is this a right approach to display the number to which
the sms is send

error is
java.lang.RuntimeException: Error receiving broadcast Intent
{ action=SMS_SENT } in seaant.android.panicmessag...@437489e8
 Caused by: java.lang.NullPointerException

may be i misunderstood the concept of intent ,Help me to solve this

Other Threads

1. Code Coverage with EMMA or Ant

hi guys i'm tryng to do some testing in my android application,

I've set-up my project in eclipse and I can successfully run my code.
I've alredy written some JUnit test cases, now I'm tryng to generate a
code coverage report. However it seems that there are different ways
to accomplish this and the documantation is not very clear.

Can someone tell me what's the best solution considering that I've all
my code in eclipse?
What steps do I need to take to get the reports.

(I've seen some posts about EMMA but the whole thing seems hackish and
I'm not sure how it works when with eclipse, i.e. when the project is

Thank you in advice,


2. Hello World! java.lang.NullPointerException error


Did you find a resolution to the problem because I've got the same one
and I'd like to know how you resolved it.

Thanks in advance,


> using:

3. How to get available size for table?

4. Resources find rule

5. How do I get handle back after navigating through various web pages

6. Get current location

7. IllegalArgumentException when trying to run an OpenGL ES 2.0 application