How to disable date setting on Android?

we have an application that will record the correct date and time when the user fires the event. we do not want the user to change the date and time to the elapsed time. How to disable date and time settings at the Android system level?

+6
source share
1 answer

Even if you can find some kind of hack this, this is not what you want to do. The best solution would be to listen for the ACTION_TIMEZONE_CHANGED, ACTION_TIME_CHANGED and ACTION_DATE_CHANGED events, and then change your previous time accordingly. This is actually very easy to do, I can provide sample code if you need help.

TimeChanged.java

package com.example.stackoverflow17462606; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class TimeChanged extends BroadcastReceiver { public TimeChanged() { } @Override public void onReceive(Context context, Intent intent) { // Do whatever changes you need here // you can check the updated time using Calendar c = Calendar.getInstance(); } } 

AndroidManifest.xml

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.stackoverflow17462606" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="17" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <receiver android:name="com.example.stackoverflow17462606.TimeChanged" android:enabled="true" android:exported="true" > <intent-filter> <action android:name="android.intent.action.TIMEZONE_CHANGED"/> <action android:name="android.intent.action.TIME_SET"/> <action android:name="android.intent.action.DATE_CHANGED"/> </intent-filter> </receiver> </application> </manifest> 

Remember that this will only work if you once launched the application on the device (to prevent applications from starting after installation)

+10
source

Source: https://habr.com/ru/post/948665/


All Articles