BroadcastReceiver Vs WakefulBroadcastReceiver

There is only one difference between BroadcastReceiver and WakefulBroadcastReceiver. When you receive the broadcast inside onReceive() method, Suppose, BroadcastReceiver : It is not guaranteed that CPU will stay awake if you initiate some long running process. CPU may go immediately back to sleep. WakefulBroadcastReceiver : It is guaranteed that CPU will stay awake until you … Read more

Light up screen when notification received android

PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE); boolean isScreenOn = pm.isScreenOn(); Log.e(“screen on……..”, “”+isScreenOn); if(isScreenOn==false) { WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |PowerManager.ACQUIRE_CAUSES_WAKEUP |PowerManager.ON_AFTER_RELEASE,”myApp:MyLock”); wl.acquire(10000); WakeLock wl_cpu = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,”myApp:mycpuMyCpuLock”); wl_cpu.acquire(10000); }

PowerManager.PARTIAL_WAKE_LOCK android

The answer by @paha misses an important point : IntentService is not enough. Between onReceive() ends and the IntentService is started the phone might fall asleep again. You need a (static) lock to bridge this gap – this is implemented in Mark Murpphy’s WakefulIntentService So keep the AlarmManager and receiver but launch a WakefulIntentService from … Read more

Turn off screen on Android

There are two choices for turning the screen off: PowerManager manager = (PowerManager) getSystemService(Context.POWER_SERVICE); // Choice 1 manager.goToSleep(int amountOfTime); // Choice 2 PowerManager.WakeLock wl = manager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, “Your Tag”); wl.acquire(); wl.release(); You will probably need this permission too: <uses-permission android:name=”android.permission.WAKE_LOCK” /> UPDATE: Try this method; android turns off the screen once the light level is low … Read more