androidandroid-studioscreen-lock

Creating an app that run everytime I turn the screen on


I'm using android studio and I was wondering if there's a way to make an app that run every time I turn on the screen (e.g. screen lock). I know this has been asked before, but I can't understand where to put the code for this.. please help


Solution

  • <!-- SCREEN_ON BroadCast intent-filter -->  
    < receiver android: name = ".broadcast.LockScreenReceiver" >
      < intent - filter >
      < action android: name = "android.intent.action.SCREEN_ON" / >
      < action android: name = "android.intent.action.SCREEN_OFF" / >
      < action android: name = "android.intent.action.USER_PRESENT" / >
      < /intent-filter>  
    </receiver >
    
    
      //receive broadcast and do something
      public void onReceive(Context context, Intent intent) {
        if (Intent.ACTION_USER_PRESENT.equals(intent.getAction())) {
          Log.e("scrennOn", "I'm comming!");
        }
      }