0

我正在使用媒体播放器进行电话响铃,我想在电话响铃时打开屏幕,请帮助我

提前致谢

4

1 回答 1

0

要获得振铃事件:

private PhoneStateListener  phoneStateListener  = new PhoneStateListener() {
                                                        @Override
                                                        public void onCallStateChanged(int state, String incomingNumber) {

                                                            switch (state) {
                                                                case TelephonyManager.CALL_STATE_RINGING:
                                                                    break;
                                                                case TelephonyManager.CALL_STATE_OFFHOOK:
                                                                    break;
                                                                case TelephonyManager.CALL_STATE_IDLE:
                                                                    break;
                                                            }
                                                        }
                                                    };

设置观察者:

    try {
            TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
            telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
        }
        catch (SecurityException e) {
            // don't have READ_PHONE_STATE
        }

并保持屏幕开启

解决方案1:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

解决方案 2:

<uses-permission android:name="android.permission.WAKE_LOCK"/>

yourwakelock = getContext().getSystemService(Context.POWER_SERVICE).newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, getClass().getName());

目前为止就这样了

于 2013-07-18T09:52:01.277 回答