BroadcastReceiver to log PhoneState during of my activity

by Mak » Sun, 15 Mar 2009 11:07:59 GMT


Sponsored Links
 Hi.
I'd like to log some telephonyManager and phoneState events as
onCellLocationChanged and onCallStateChanged.. during my activity.
Cause i need this for more than one activity,  i created an
broadcastReceiver that receives broadcasts, when something special in
my activities happen.

But my problem is that i can't define a telephonyManager in the
broadcastReceiver
like in an activity.
Why wont the following work in?

.............
TelephonyManager tmanager = (TelephonyManager)
                                      getSystemService
(Context.TELEPHONY_SERVICE);
tmanager.listen( new PhoneStateListener(){

        public void onCallStateChanged(int state, String incomingNumber) {
                super.onCallStateChanged(state, incomingNumber);
                callstate =  state;
       }

}, PhoneStateListener.LISTEN_CALL_STATE);
...........

Why is getSystemService(String) undefined for a broadcastReceiver?
Where is my fault?
Thanks for an answer.
Mak
--~--~---------~--~----~------------~-------~--~----~