如何在媒体播放器android中使用setWakeMode方法?

时间:2012-08-28 14:11:42

标签: android-mediaplayer

我正在使用媒体播放器进行电话铃声,我想在手机响铃时屏幕显示请帮帮我

提前致谢

1 个答案:

答案 0 :(得分: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());

现在一切都是