如何在android上禁用日期时间设置?

我们有一个应用程序,它将记录用户触发事件时的正确日期和时间.
我们不希望用户将日期和时间更改为已过去的时间.
如何在 Android系统级别禁用日期和设置?

解决方法

即使你能找到一些黑客来做这件事,这也不是你想做的事情.更好的解决方案是侦听ACTION_TIMEZONE_CHANGED,ACTION_TIME_CHANGED和ACTION_DATE_CHANGED事件,然后相应地更改您之前的时间.这实际上非常容易,如果您需要帮助,我可以提供示例代码.

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>

请记住,如果您在设备上启动了一次应用程序(仅防止应用程序在安装后自行运行),此操作才会触发

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...