Locked screen detection? Ionic notifications


#1

I want to send notifications but only when the screen is locked or the app is minimalized, is there any way to detect those two stances?


#2

Notifications are normally sent from a server to a device - so there is no connection to the device.

Lets turn the question around: In which instances do you NOT want to receive a notification?


#3

When user is currently browsing the application


#4

What should happen after the device received a push notification and the user then starts the app?

If the answer is “nothing special” you could just implement normal push applications and not do anything in the app to show it. Then the notification text only appears on the OS level, which only happens when the app is not currently open.


#5

so what should I use instead of local-notifications?


#6

Normal push notifications, e.g. Ionic Push or OneSignal.


#7

but I dont want to notify every user that match certain criteria from the server, I want something like:
user is clicking “show notifications every 2 minutes” button in app and he will reveice those notifications, without server, just simple alerts on phone’s lock screen


#8

Then do the same with local notifications: Schedule them, don’t handle them by showing something in the app but just “swallow” the message.


#9

could you elaborate because i am not sure if i get this, i just use

this.localNotifications.schedule({
            id: 0,
            text: 'You are currently not working',
            sound: this.platform.is('android') ? 'file://sound.mp3' : 'file://beep.caf',
          });

an i am not sure how it works out since i dont run emulator


#10

Yes, use https://ionicframework.com/docs/native/local-notifications/


#11

and it will notify only in locked screen?


#12

No idea. Read the docs, test it, find a way to configure it.