we have an application which will record the right date&time when user trigger an event. we don't want user to change the date&time to a passed time. How to disable date&setting on Android system level?
Even if you could find some hack to do this, this is not something you want to do. A better 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>
Please remember that this will only fire if you've launched your app once on the device (to prevent apps from running themselves once their installed)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With