Answer the question
In order to leave comments, you need to log in
Wake lock not working?
WakeLock not working on android. There is an application - a small server on sockets. Everything works until the screen turns off, after 30 seconds the server becomes unavailable. I found out on the Internet that in order for the processor to work even after turning off the screen, you need to use WakeLock, but for some reason this method does not work for me. I did this:
PowerManager pm = (PowerManager) this.getSystemService(this.POWER_SERVICE);
wl = pow.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock");
<uses-permission android:name="android.permission.WAKE_LOCK" />
Notification notif;
@Override
public void onCreate() {
Notification.Builder builder = new Notification.Builder(this).setSmallIcon(R.drawable.ic_launcher);
if (Build.VERSION.SDK_INT < 16) {
notif = builder.getNotification();
} else {
notif = builder.build();
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
startForeground(777, notif);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question