[android-developers] Re: How can we register broadcastreceiver dynamically (in java file)

2011-12-22 Thread Sveinung Kval Bakken (Giant Leap Technologies AS)
http://developer.android.com/reference/android/content/Context.html#registerReceiver%28android.content.BroadcastReceiver,%20android.content.IntentFilter%29

Just use Context's registerReceiver(), e.g. from your application's
onCreate(). Remember to unregister the receiver, from an activity the
lastest point to unregister would be in onDestroy.

registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// Do something
}
}, new IntentFilter(SOME INTENT));

On Dec 22, 9:01 am, surabhi jain surabhi17.j...@gmail.com wrote:
 h,

 I want to send sms but register receiver dynamically.

 plz send me the source code.

 Thanks to all.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: How can we register broadcastreceiver dynamically (in java file)

2011-12-22 Thread surabhi jain
I register receiver like that in my activity class

registerReceiver(sendreceiver, new IntentFilter(SMS_SENT));

 private BroadcastReceiver sendreceiver = new BroadcastReceiver()
 {
 @Override
 public void onReceive(Context context, Intent intent)
 {
 String info = Send information: ;

 switch(getResultCode())
 {
 case Activity.RESULT_OK: info += send
successful; break;
 case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
info += send failed, generic failure; break;
 case SmsManager.RESULT_ERROR_NO_SERVICE: info
+= send failed, no service; break;
 case SmsManager.RESULT_ERROR_NULL_PDU: info +=
send failed, null pdu; break;
 case SmsManager.RESULT_ERROR_RADIO_OFF: info
+= send failed, radio is off; break;
 }

 Toast.makeText(getBaseContext(), info,
Toast.LENGTH_SHORT).show();

 }
 };

and in receiver class in which i am extending broadcastReceiver

I am getting the action and switch to activity class

But my receiver is not registering.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: How can we register broadcastreceiver dynamically (in java file)

2011-12-22 Thread lbendlin
how do you know it is not registering? and what does getResultCode() do?

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: How can we register broadcastreceiver dynamically (in java file)

2011-12-22 Thread surabhi jain
I think not sure that getResultCode() gives the status of sms that our sms
sent or not (no service), it passes integer value and according to that we
can fing out the sms status.

when I installed my application on emulator then after sending sms, I want
that my another activity should launch, but it would not work and I also
used Logs for getting the flow, but nothing I have seen.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en