Code example for PowerManager

Methods: newWakeLock, sleep

0
 
    @SuppressWarnings("deprecation") 
    private void turnOnScreen(SharedPreferences mPrefs, PowerManager pm) {
    	if(mPrefs.getBoolean("status-bar", false)) {
    		try {    	 
                Thread.sleep(3000);
            } 
            catch (Exception e) {
            } 
    	} 
    	 
        int time = mPrefs.getInt("time", 10);
 
        PowerManager.WakeLock wl;
        if(mPrefs.getBoolean("bright", false))
            wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "Screen Notifications");
        else 
            wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "Screen Notifications");
        wl.acquire();   
         
        try { 
        	if(mPrefs.getBoolean("status-bar", false)) {
	        	Object sbservice = getSystemService("statusbar");
	        	Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
	        	Method showsb = statusbarManager.getMethod("expand");
	        	showsb.invoke(sbservice);
        	} 
        } catch (Exception e) {
        	Log.d("screen-notifications", "Exception: " + e);
        } 
         
        try {    	 
            Thread.sleep(time * 1000);
        } 
        catch (Exception e) {
        } 
        finally { 
        	wl.release();