0

I m having problems with Wake lock. I followed this: http://developer.android.com/reference/android/os/PowerManager.html and several other tutorials. I have pending intent which launch other activity. Here I need to wake up display for user to finish some job. However, with code below, display is dark and media player is playing. Could you tell me what I am doing wrong?

pending intent

public class AlarmReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    Intent lightIntent = new Intent(context, lightWakeup.class);
    lightIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //volani aktivity z broadcast receiveru
    context.startActivity(lightIntent);
}

}

lightWakeup.class

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_light_wakeup);

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag");
    wl.acquire();
    //Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    //setSupportActionBar(toolbar);
    text = (TextView)findViewById(R.id.textView);
    //zapnuti hudby

    MainPage.mp.setVolume(100, 100);
    MainPage.mp.setLooping(true);
    MainPage.mp.start();

    sensorManager = (SensorManager) getSy..

Manifest: <uses-permission android:name="android.permission.WAKE_LOCK">

1 Answers1

0

This helped

KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
final KeyguardManager.KeyguardLock kl = km.newKeyguardLock("MyKeyguardLock");
kl.disableKeyguard();

PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
        | PowerManager.ON_AFTER_RELEASE, "MyWakeLock");
wakeLock.acquire();
Salmaan
  • 3,543
  • 8
  • 33
  • 59