Tuesday, 15 May 2012

android - i can send value from my activity to broadcastreceiver but i can't use it for long time -



android - i can send value from my activity to broadcastreceiver but i can't use it for long time -

actually in app want send message when phone making phone calls...here app installing time asking parent number , number sending broadcast receiver activity first activity...its received there , toasting value..but when making phone phone call value alter null...can help me access value @ phone calling time ..is possible ??how..thank code given below...

in first activity sending value broadcast receiver:

try { toast.maketext(getapplicationcontext(), "try", toast.length_long).show(); intent in = new intent("my.action.string"); in.putextra("parent", parent);//this string sending broadcast receiver sendbroadcast(in); } grab (exception e) { // todo: handle exception e.printstacktrace(); }

and broadcast receiver is:

public class mybroadcast extends broadcastreceiver { string out_number; string myparent; @override public void onreceive(context context, intent intent) { // todo auto-generated method stub myparent = intent.getextras().getstring("parent"); //this sting access number first , alter null @ making phone phone call final string my=myparent; toast.maketext(context, "broadcst"+myparent, toast.length_long).show(); if (intent.getaction().equals("android.intent.action.new_outgoing_call")) { out_number=intent.getstringextra(intent.extra_phone_number); toast.maketext(context, "broadcst"+my+" "+out_number, toast.length_long).show(); smsmanager sm=smsmanager.getdefault(); sm.sendtextmessage(myparent, "5554", "calling..to"+myparent, null, null); //5554 emulator number check in emulator toast.maketext(context, "send"+out_number, toast.length_short).show(); } } }

/* * receiver intended incoming calls read though phone * state more details see android.content.broadcastreceiver * * @author parul * */ public class incomingcallreciever extends broadcastreceiver { public static string log = "incomingcall"; /* * (the onreceive invoked when receive arbitrary intent * incoming phone call service) * * @see android.content.broadcastreceiver#onreceive(android.content.context, * android.content.intent) */ @override public void onreceive(context context, intent intent) { // todo auto-generated method stub log.v(log, "incomingcallreciever"); bundle bundle = intent.getextras(); if (bundle == null) { return; } string state = bundle.getstring(telephonymanager.extra_state); log.v(log, "" + state); if (state.equalsignorecase(telephonymanager.extra_state_ringing)) { string phonenumber = bundle .getstring(telephonymanager.extra_incoming_number); toast.maketext(context, "the incoming number ..." + phonenumber, toast.length_short).show(); log.v(log, "incomming number ... " + phonenumber); } else { log.v(log, "test 2 "); } } }

android broadcastreceiver

No comments:

Post a Comment