PowerManager-亮屏跟灭屏的实现

今天在修改代码的时候,用到了亮屏跟灭屏的功能,现在总结下屏幕亮跟灭的相关代码,如下

1.屏幕从锁定状态到变量

 

//亮屏实现代码

 PowerManager powerManager = (PowerManager) (context.getSystemService(Context.POWER_SERVICE));

 PowerManager.WakeLock wakeLock = null;

 wakeLock=powerManager.newWakeLock(PowerManager.FULL             _WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP

                        | PowerManager.ON_AFTER_RELEASE, "MMS_wake_lock");

//设置屏幕亮的时间

 long wakeUpTime = 0; 

                try {

//从系统变量里面读取

                    ContentResolver cr = context.getContentResolver();

                    wakeUpTime = android.provider.Settings.System.getInt(cr, Settings.System.SCREEN_OFF_TIMEOUT);

                } catch (SettingNotFoundException e) { 

                    MmsLog.e(TAG, "Exception occured in wakeupScreen()");

                } 

//设置时间 如果没有设置,默认常亮  

                wakeLock.acquire(wakeUpTime);

//释放资源

                if (wakeLock != null) {

                    wakeLock.release();

                }    

         

2.屏幕从

你可能感兴趣的:(manager)