I listen to the receiver wake up the screen. Is it possible to find out why the screen was awakened? (The user pressed the unlock button, or some program (Skype, alarm clock, etc.))

    1 answer 1

    You can try to implement a certain listener, which is included at the time of awakening (interception of Broadcast):

    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List< ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(MAX_PRIORITY); for(int i=0; i < taskInfo.size(); i++) String activityName = taskInfo.get(i).topActivity.getClassName(); 

    and see what is on the stack of activation managers, the last or the last but one, this will obviously be the task that generated the broadcasts.

    PS Perm is needed:

     <uses-permission android:name="android.permission.GET_TASKS"/> 
    • Not a bad decision. Interestingly, how can you listen to the change in these tasks? Or, for example, to find out if a task has opened or closed? - azat