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. Computers

Computer - Wikipedia, the free encyclopedia
The first devices that resemble modern computers date to the mid-20th
century ( 1940945), although the computer concept and various
machines similar to ...



2. New Maps API TOS'

I'm just done reading the the new Maps API TOS'. Looks like this is
our framework for going live now.
* I personally find the clarification with respect to permissible
connections to tracking systems (section in 8.7) very helpful. I
suppose this clears my work and hopefully many others' as well
* I cannot remember where the lengthy Copyright notice requirement
("(c) 2007 TeleAtlas, AND, Europa Technolgies, Kingway...") originated
at; I suppose this is gone now?
* Section 9 is the infamous Google contents grab. So they really want
to go live with this? As far as apps using the Maps API are concerned
- am I getting this right: Section 9 essentially means that apps (.apk
file) that use the Maps API, and which are released in Google
Marketplace, can be redistributed through a Google-related
organization without the consent of the copyright holder?


3. JRuby

4. How to load create a view programmatically with parameters from a layout file

5. If your wondering if users are out there...

6. Wireless IP interface with Android

7. SlideME: Ready for Stocking of Applications