I am doing an android application. In my project I am checking phonestates using broadcast receiver.Using the folowing code I am checking my phonestate.
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Bundle bun=intent.getExtras();
if(bun!=null){
String state=bun.getString(TelephonyManager.EXTRA_STATE);
Log.w("DEBUG", state);
if(state.equals(TelephonyManager.EXTRA_STATE_RINGING)){
String phoneno=bun.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
Toast.makeText(context, "phone no. is"+phoneno, Toast.LENGTH_LONG).show();
}
}
}
Now i want control this application from activity. I mean using an button i have start the broadcast and using an off button i have to close the broadcast run.the second problem is i want run the application when the application is in closed state too. So i think I have call a service from activity and that service make that broadcast receiver to run in the background. And if i want to stop my application’s processing open app and click the button to off. Help me friends..
You can ,
When click on
Registered your broadcast
when click off
unregistered your broadcast