Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8faee0b

Browse filesBrowse files
isUsingNetworkProvidedTime()
Useful in situations where you want to verify that the device has a correct time set, to avoid fraud, or if you want to prevent the user from messing with the time and abusing your "one-time" and "expiring" features.
1 parent 64555be commit 8faee0b
Copy full SHA for 8faee0b

1 file changed

+13Lines changed: 13 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/utilcode/src/main/java/com/blankj/utilcode/util/TimeUtils.java‎

Copy file name to clipboardExpand all lines: lib/utilcode/src/main/java/com/blankj/utilcode/util/TimeUtils.java
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ protected Map<String, SimpleDateFormat> initialValue() {
3636
private static SimpleDateFormat getDefaultFormat() {
3737
return getSafeDateFormat("yyyy-MM-dd HH:mm:ss");
3838
}
39+
/**
40+
* Checks whether the device is using Network Provided Time or not.
41+
* Useful in situations where you want to verify that the device has a correct time set, to avoid fraud, or if you want to prevent the user from messing with the time and abusing your "one-time" and "expiring" features.
42+
* @return {@code true}: yes<br>{@code false}: no
43+
*/
44+
public static boolean isUsingNetworkProvidedTime() {
45+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
46+
return Settings.Global.getInt(Utils.getApp().getContentResolver(), Settings.Global.AUTO_TIME, 0) == 1;
47+
} else {
48+
return android.provider.Settings.System.getInt(Utils.getApp().getContentResolver(), android.provider.Settings.System.AUTO_TIME, 0) == 1;
49+
}
50+
}
51+
3952

4053
@SuppressLint("SimpleDateFormat")
4154
public static SimpleDateFormat getSafeDateFormat(String pattern) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.