How to detect system time change


#1

Hello,

Is there a way in ionic 2 to detect that the user has changed the system time while the app is running both for Android and iOS.

Thanks


#2

Hi. The first idea that comes to my mind is making an Observable that runs in a given interval. Don’t know if there’s a way to make this on a cleaner way, something like capturing a system event or something like that.
IMHO using an Observable to solve this could possibly lead to memory leaks if you’re not careful enough.
Best regards.
J


#3

Interesting question, I would see if there is any kind of system notification/event broadcast when the system time is changed.

How do native apps handle this? Maybe you need a Cordova plugin that does the same and forwards the information to your Ionic app.


#4

I could not find any cordova plugin that could serve this purpose. How can one listen to native events?


#5

You could either create your own cordova plugin to handle this, or you could try this plugin:
cordova-plugin-intent in combination with the android.intent.action.TIME_SET intent.

Not sure how well the plugin works or anything, but there you go.


#6

SigmundFroyd, thanks. This could be a good starting point, I will try it and post my findings.


#7

Excuse me, could you solve the problem?


#8

Unfortunately I couldn’t. This was beyond my ionic skills.