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. Motorola Cliq + Motorola Droi

as per subject, nyari moo cliq dan droid (cdma)
kalau ada yang punya, boleh tawarin via japri ya.
batangan oke, kondisi klo bisa sih mulus.


sent from HTC Legend

"Indonesian Android Community [id-android]" 

2. Google gila :-)

You must try this.

Google lagi acara I/O kasih lihat buka apa di web di pc, tiba2 nexus
menerima yg sama.
Nah kemarin malem sudah direlease softwarenya , namanya chrome extension.

Pertama install di android, dan registerkan android kita memakai alamat
email google dan centang auto launch.

Download software extension untuk chrome browser atau fire fox.

Nanti di chrome di pc , dipojok kanan ada gambar nexus. Daftarkan juga
dengan alamat email yg sama.

Misal lagi buka web di chrome, klik logo nexus....Bam! Web yg sama muncul si
android kita.
Manteb, ngga usah salin2 alamat web.

Cocok misal lagi baca isi web di pc, trus harus buru2 pergi, klik extension
ini dan terusin baca webnya di android :-)

Hebat google, dan kabarnya ini akan dikembangkan untuk music.
Kita punya lagu apa di pc, klik send to android, suaranya nongol di android,
streaming hahahaha.

Donlot disini extension



Lucky Sebastian

"Indonesian Android Community [id-android]" 

3. Buat yang mesan battery BP6X kloter lalu (4-8 Mei

4. Any guidelines for handling the Headset and Bluetooth AVRC buttons in Froyo?

5. Digest for android-developers@googlegroups.com - 25 Messages in 18 Topics

6. Battery & EBC for Motorola BP6X, Nexus On

7. Error playing multiple sounds