Is it possible to determine when the screen is turned on by the user (Android)?

I found a message from two years ago that someone said this was not possible. I also found that I can use ACTION_USER_PRESENT to detect when the user unlocks the screen, but can I determine when the user will turn on the screen (by any action)?

EDIT: I want to know when the user presses any button or does anything else that can turn on the screen

+4
source share
3 answers

I started writing this as a comment, but it turned out to be too big.

. , , -, , . , , )? , :

ActivityManager am = (ActivityManager) this .getSystemService(ACTIVITY_SERVICE);
List<RunningTaskInfo> taskInfo = am.getRunningTasks(1);
ComponentName componentInfo = taskInfo.get(0).topActivity;
Log.d(WebServiceHelper.TAG, "CURRENT Activity ::" + taskInfo.get(0).topActivity.getClassName()+"   Package Name :  "+ componentInfo.getPackageName());

, - , , / . , - , , , :

KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
boolean locked = km.inKeyguardRestrictedInputMode();

, . .

+1

Intent.ACTION_SCREEN_ON, , .

public class MyReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
            // your code here

        }
    }
}

, .

+4

?

@Override
public void onConfigurationChanged (Configuration newConfig)

, :

android:configChanges="orientation" >
-1

All Articles