- Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathLocalUtils.java
More file actions
Latest commit
93 lines (72 loc) · 2.14 KB
/
Copy pathLocalUtils.java
File metadata and controls
93 lines (72 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
packagecom.realmo.utils;
importandroid.content.Context;
importandroid.telephony.TelephonyManager;
importandroid.text.TextUtils;
importjava.util.Locale;
/**
* Created by realmo on 16/8/15.
*/
publicclassLocalUtils {
/**
* 判断国家是否是国内用户
*
*方法一
*
* @return
*/
publicstaticbooleanisCN(Contextcontext) {
TelephonyManagertm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
StringcountryIso = tm.getSimCountryIso();
booleanisCN = false;//判断是不是大陆
if (!TextUtils.isEmpty(countryIso)) {
countryIso = countryIso.toUpperCase(Locale.US);
if (countryIso.contains("CN")) {
isCN = true;
}
}
returnisCN;
}
/**
* 判断系统语言环境
* @return
*/
publicstaticbooleanisZh(Contextcontext) {
Localelocale = context.getResources().getConfiguration().locale;
Stringlanguage = locale.getLanguage();
if (language.endsWith("zh"))
returntrue;
else
returnfalse;
}
/**
* 方法二
*/
/** 查询手机的 MCC+MNC */
privatestaticStringgetSimOperator(Contextc) {
TelephonyManagertm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE);
try {
returntm.getSimOperator();
} catch (Exceptione) {
}
returnnull;
}
/** 因为发现像华为Y300,联想双卡的手机,会返回 "null" "null,null" 的字符串 */
privatestaticbooleanisOperatorEmpty(Stringoperator) {
if (operator == null) {
returntrue;
}
if (operator.equals("") || operator.toLowerCase(Locale.US).contains("null")) {
returntrue;
}
returnfalse;
}
/** 判断是否是国内的 SIM 卡,优先判断注册时的mcc */
publicstaticbooleanisChinaSimCard(Contextc) {
Stringmcc = getSimOperator(c);
if (isOperatorEmpty(mcc)) {
returnfalse;
} else {
returnmcc.startsWith("460");
}
}
}