denglixuan1996
邓富贵儿
2016-08-21 02:39

android锁屏状态下弹出闹钟对话框

我现在的情况是当闹钟到点时会唤醒屏幕,闹钟也会响,但是不能在锁屏之上显示,得先解锁才能看见闹钟时间到了的对话框。我在手机上测试就可以正常显示,但是在平板上不行,我用了FLAG_SHOW_WHEN_LOCK,官方说这个FLAG只有在top-most full-screen window才有效,但我不知道这是什么意思。我想让闹钟对话框在锁屏上显示。有没有大神有啥解决办法呀。这是我的代码:
对话框的activity()。

  <activity
            android:name=".activity.AlarmTrigger"
            android:configChanges="orientation|keyboardHidden"
            android:excludeFromRecents="true"
            android:hardwareAccelerated="true"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:theme="@android:style/Theme.Wallpaper.NoTitleBar"/>

Activity的代码:

public class AlarmTrigger extends Activity {
    protected void onCreate(Bundle savedInstanceState) {
        if (Log.LOG_ENABLE)
            Log.v("AlarmTrigger.onCreate()");
        super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        mDataCenter.openDataBase();
    }
    protected void onResume() {
        if (Log.LOG_ENABLE)
            Log.v("AlarmTrigger.onResume()");
        super.onResume();
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        MobclickAgent.onResume(this);
        if (mKeyguardLock == null) {
            mKeyguardLock = mKeyguardManager.newKeyguardLock(Log.LOG_TAG);
            try {
                mKeyguardLock.disableKeyguard();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (mSharedPreferences.getBoolean(Preferences.KEEP_SCREEN_ON, false)) {
            AlarmAlertWakeLock.acquireScreenWakeLock(this);
        }
        mRingtoneDuration = mSharedPreferences.getInt(
                Preferences.RINGTONE_DURATION, 15) * 1000;
        if (mRingtoneDuration != -1000) {
            FLAG_IS_LOPPING = true;
            mTimer = new Timer(false);
            mTimer.schedule(new TimerTask() {
                @Override
                public void run() {
                    if (mIsVibrate)
                        mVibrator.cancel();// 取消震动
                    myMusicManager.stopPlaying();
                    mBabyCarePlus.setTimerTriggering(false);
                    releaseLocks();
                }
            }, mRingtoneDuration);
        }
        showDialog(SHOW_ALARM_DIALOG);
        boolean isAutoSnooze = mSharedPreferences.getBoolean(
                Preferences.AUTO_SNOOZE, false);
        if (isAutoSnooze) {
            startAutoSnoozeThread();
        }
    }
    protected void onDestroy() {
        mDataCenter.closeDataBase();
        super.onDestroy();
    }
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
        if (mSharedPreferences.getBoolean(Preferences.KEEP_SCREEN_ON, false)) {
            releaseLocks();
        }
        if (mKeyguardLock != null) {
            try {
                mKeyguardLock.reenableKeyguard();
            } catch (Exception e) {
                e.printStackTrace();
            }
            mKeyguardLock = null;
        }
    }
    private void releaseLocks() {
        AlarmAlertWakeLock.release();
    }
}

中间省略了些无关代码,望大神给解答!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答