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
 hi,
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
sms
public void onClick()
{
      for (int j = 0; j<phonenos.length;j++)
               {
        sendSMS(phonenos[j],mess);
              }
}
 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()
   {
       super.onStart();
       br_send=new BroadcastReceiver(){
           @Override
           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()
   {
       super.onStop();
       unregisterReceiver(br_del);
}
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
error
Thanks
Ganesh
--~--~---------~--~----~------------~-------~--~----~