Skip to content Skip to sidebar Skip to footer

Trouble With Reading Phone State

I want to perform some operation (Pause game) in my application when a call came. But reading the phone state is not working. I have given permission(READ_PHONE_STATE) in the manif

Solution 1:

Have you written the following line :

 telephonyManager.listen(listener,PhoneStateListener.LISTEN_CALL_STATE);

Solution 2:

when your listener has be created, you need invoke `public void listen (PhoneStateListener listener, int events)' to listen.

also, you can try this: create a broadcatst receiver handle the action android.intent.action.PHONE_STATE,

code example:

public class PhoneStateReceiver extends BroadcastReceiver {

private TelephonyManager manager;

@Override
public void onReceive(Context context, Intent intent) {
    if (manager == null) {
        manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    }
    String action = intent.getAction();
    System.out.println(action);
    System.out.println("current phone state:" + manager.getCallState());
}

}


Post a Comment for "Trouble With Reading Phone State"