Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable date time setting on android?

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?

like image 346
freevictor Avatar asked Jul 04 '13 02:07

freevictor


1 Answers

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)

like image 65
Ryan S Avatar answered Nov 10 '22 07:11

Ryan S