android - how can telephony manager conditionally listen to multiple PhoneStateListener's events? -
i'm having telephony manager listening call_state.
now want additionally listen data_connection_state , service_state using same telephony manager under different conditions (plz refer following code snippet)
how can it?
my current code seems not work properly
telephonymanager = (telephonymanager) getsystemservice(context.telephony_service); phonestatelistener = new phonestatelistener() { public void oncallstatechanged(int state, string incomingnumber) { switch (state) { case telephonymanager.call_state_idle: case telephonymanager.call_state_offhook: // break; case telephonymanager.call_state_ringing: break; } super.oncallstatechanged(state, incomingnumber); } public void onservicestatechanged(servicestate servicestate) { switch (servicestate.getstate()) { case servicestate.state_emergency_only: case servicestate.state_out_of_service: // break; default: break; } super.onservicestatechanged(servicestate); } public void ondataconnectionstatechanged(int state) { switch (state) { case telephonymanager.data_disconnected: // break; default: break; } super.ondataconnectionstatechanged(state); } }; btnrun.setonclicklistener(new onclicklistener() { public void onclick(view v) { if (some conditions) { telephonymanager.listen(phonestatelistener, phonestatelistener.listen_call_state); } if (some conditions) { // additionally listen more states telephonymanager .listen(phonestatelistener, phonestatelistener.listen_data_connection_state); } if (some conditions) { // additionally listen more states telephonymanager.listen(phonestatelistener, phonestatelistener.listen_service_state); } } }
is there suggestion please?
thank all!
Comments
Post a Comment