I am trying to figure out how to wake and unlock the phone with a service. I have been referring to this post but, I can\'t figure out why it isn\'t working. This is the cod
There is WakefulBroadcastReceiver which does this for you. Example use:
import android.content.Context; import android.content.Intent; import android.os.SystemClock; import android.support.v4.content.WakefulBroadcastReceiver; import android.util.Log; public class SimpleWakefulReceiver extends WakefulBroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // This is the Intent to deliver to our service. Intent service = new Intent(context, SimpleWakefulService.class); // Start the service, keeping the device awake while it is launching. Log.i("SimpleWakefulReceiver", "Starting service @ " + SystemClock.elapsedRealtime()); startWakefulService(context, service); } }
After completing the action in the service, call SimpleWakefulReceiver.completeWakefulIntent(intent) to release the wake lock.
(as @Force already gave you the details about the wakeLock, they need not be repeated here ;-)
Mind that the class is deprecated from api level 26.1.0, reference here