is there way detect when android system clock has been reset by user in android?
i'm designing app uses system time determine when user @ place @ time, , don't want rely on network availability @ point. therefore know when user has changed system clock, can't "cheat".
yes, there is. action_time_changed
intent broadcast when device time changed, , can have method trigger when intent detected.
this intent has been in android since api level 1, should work on platform might need compatible with.
you'll need handle broadcast broadcastreceiver
:
public class timechangedreceiver extends broadcastreceiver { @override public void onreceive(context context, intent intent) { //do whatever need } }
you'll need add manifest:
<receiver android:name=".timechangedreceiver"> <intent-filter> <action android:name="android.intent.action.time_set" /> </intent-filter> </receiver>
this let android know trigger receiver when type of intent detected.
it appears though doesn't care edits time, not trigger on automatic adjustments when synced network. if lose network , regain it, though, fire since time different (assuming using automatic network time).
however, while clocks on cell phones not particularly accurate (since rely on syncing time signals receive) in experience absolutely should not lose more 30 seconds or minute per hour, @ absolute maximum, if time change small can perhaps assume automatic. leap seconds, when added, produce time change message, although these small , infrequent.
you can use connectivitymanager
keep track of whether phone has connection or not , can change behavior based on (i.e. long network connectivity there, , time automatic/network time, ignore time changes or something) can't find intents regarding losing/regaining network connectivity have use polling method.
Comments
Post a Comment