title: Wake phone from unlock screen android
body: <p>Hеllo guуs, I want to unlock the phone with service. I'm using alarm manager.
  Receiver and Service were added to manifest
  and also permissions for RECEIVE_BOOT_COMPLETE and WAKE_LOCK
  AlarmReceiver</p>
  
  <pre><code>public class AlarmReceiver extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
          setAlarms(context);
      }
  
      public static void setAlarms(Context context) {
          cancelAlarms(context);
          PendingIntent pIntent = createPendingIntent(context);
          Calendar calendar = Calendar.getInstance();
          setAlarm(context, calendar, pIntent);
      }
  
      @SuppressLint("NewApi")
      private static void setAlarm(Context context, Calendar calendar, PendingIntent pIntent) {
          AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
          if (android.os.Build.VERSION.SDK_INT &gt;= android.os.Build.VERSION_CODES.KITKAT) {
              alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pIntent);
          } else {
              alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pIntent);
          }
      }
  
      public static void cancelAlarms(Context context) {
                      PendingIntent pIntent = createPendingIntent(context);
                      AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
                      alarmManager.cancel(pIntent);
      }
  
      private static PendingIntent createPendingIntent(Context context) {
          Intent intent = new Intent(context, AlarmService.class);
          return PendingIntent.getService(context, 777, intent, PendingIntent.FLAG_UPDATE_CURRENT);
      }
  }
  </code></pre>
  
  <p>AlarmService</p>
  
  <pre><code>public class AlarmService extends Service {
  
      public static String TAG = AlarmService.class.getSimpleName();
  
      @Override
      public IBinder onBind(Intent intent) {
          return null;
      }
  
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
  
          Intent alarmIntent = new Intent(getBaseContext(), MainActivity.class);
          alarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          alarmIntent.putExtras(intent);
          getApplication().startActivity(alarmIntent);
  
          //AlarmManagerHelper.setAlarms(this);
          Log.e("SERVICE_WORKING","YEEEES!!!!");
  
          return super.onStartCommand(intent, flags, startId);
      }
  
  }
  </code></pre>
  
  <p>MainActivity</p>
  
  <pre><code>Intent myIntent = new Intent(MainActivity.this, AlarmReceiver.class);
  PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, myIntent, 0);
  AlarmManager alarmManager=(AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
  alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis()+10000, pendingIntent);
  </code></pre>
  
  <p>It works fine, but if i lock the screen it doesn't unlock it.</p>