Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android notification of screen off/on

Tags:

android

I'm looking to see if there's a system notification I can listen for to see when the screen turns off/on. Any thoughts? Something similar to when the network connects/disconnects.

like image 948
Kevin Galligan Avatar asked Nov 17 '10 19:11

Kevin Galligan


People also ask

How do I stop my screen from turning on when I get a notification?

You can disable this by tapping your profile icon > gear icon > Notifications > uncheck “Wake Screen” from within the app.

What is Wake screen notification?

After turning on Wake screen when a notification is received, when you receive a notification, the phone will remind you. The notification content is displayed in conjunction with the lock screen notification, and you can see the notification information for the first time.

How do I turn off notifications on Android?

One example is Snapchat, a popular Android app that wakes the screen for notifications by default. You can disable this by tapping your profile icon > gear icon > Notifications > uncheck “Wake Screen” from within the app. If you don’t have any luck with the app itself, you can make the notifications “silent.”

How do I block notifications from certain apps only?

To block notifications from certain apps only, learn how to change notifications by app. Important: Settings can vary by phone. For more info, contact your device manufacturer. Tap Apps & notifications Notifications. Under "Lock screen," tap Notifications on lock screen or On lock screen. Choose Show alerting and silent notifications .

How to turn off notifications on lockscreen on Nokia 5?

Open the Settings on the device. Go to Apps & notifications. Select Notifications. Find "Notifications on lockscreen" and tap on the feature. Select "Don't show notifications" or "show alerting notifications only". The following applies to a Nokia 5 running Android 8.1 (which is more or less stock Android).

How can I see all notifications on my lock screen?

You can see all notification content on your lock screen by default. Open your phone's Settings app. Tap Apps & notifications Notifications. Under "Lock screen," tap Notifications on lock screen or On lock screen. Choose Show alerting and silent notifications. On some phones, choose Show all notification content.


1 Answers

Easiest way is to put this in your MyApplication.onCreate() method:

IntentFilter intentFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
registerReceiver(new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
            Log.d(TAG, Intent.ACTION_SCREEN_OFF);
        } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
            Log.d(TAG, Intent.ACTION_SCREEN_ON);
        }
    }
}, intentFilter);
like image 70
Chris Lacy Avatar answered Oct 05 '22 23:10

Chris Lacy