-3

I want to create a notification every x minutes a user is continuously using his/her device.

I think I'm supposed to use a background service that will listen for when the screen turns on, then I can start some sort of timer that will trigger a notification if the screen hasn't been off for x minutes (user entered time value).

I don't necessarily need a spoon-fed answer but some very clear direction or documentation would be extremely helpful because I have no idea what I'm doing! :)

Daniel Wang
  • 120
  • 9

2 Answers2

0

Let's assume that continuously using a phone means that screen is ON.

First of all, register BroadcastReceiver to keep track of ACTION_SCREEN_ON and ACTION_SCREEN_OFF events. Then use Service to keep track of time that passed and create some logic to decide, when to fire a notification.

pawelo
  • 1,405
  • 4
  • 15
  • 30
0

to detect screen on:

Intent.ACTION_SCREEN_OFF and ACTION_SCREEN_ON check out for above broadcasts registration. here https://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/ you can find a good example.

when screen is on set an alarm for x time as you want here How do I repeat a method every 10 minutes after a button press and end it on another button press user the accepted answer. When alarm time reaches check if the screen is still on if it is, create a notification. when the screen goes off turn of this alarm.

Community
  • 1
  • 1
Ahmadzkn
  • 30
  • 1
  • 8