我们有一个应用程序,它将记录用户触发事件的正确日期和时间.我们不希望用户将日期和时间更改为已通过的时间.如何在Android系统级别禁用日期和设置?
Rya*_*n S 10
即使你能找到一些黑客来做这件事,这也不是你想做的事情.更好的解决方案是侦听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();
}
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
请记住,如果您在设备上启动了一次应用程序(仅防止应用程序在安装后自行运行),此操作才会触发
| 归档时间: |
|
| 查看次数: |
3479 次 |
| 最近记录: |