doum
6 天以前 2b287056e2f59518888d05a1bbc7e5a55fbd84d5
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
package com.doumee.keyCabinet.utils;
 
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Point;
import android.os.Build;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.view.Display;
import android.view.WindowManager;
 
import com.doumee.keyCabinet.MApplication;
 
/**
 * 
 * @version 1.1.5
 * 
 */
public class LMobileInfo {
    /**
     * 判断手机号码是否正确
     * 
     * @param mobiles
     * @return
     */
    public static boolean isMobileNO(String mobiles) {
        // Pattern p = Pattern
        // .compile("^((13[0-9])|(17[0,5-8])|(15[^4,\\D])|(18[0-9]))\\d{8}$");
        // Matcher m = p.matcher(mobiles);
        // return m.matches();
        return true;
    }
 
    /**
     * 获取IMEI码
     * 
     * @return
     */
    public static String getImei() {
        TelephonyManager mTm = (TelephonyManager) MApplication.mContext.getSystemService(Context.TELEPHONY_SERVICE);
        return mTm.getDeviceId();
    }
 
    /**
     * 获取IMSI码
     * 
     * @return
     */
    public static String getImsi() {
        TelephonyManager mTm = (TelephonyManager) MApplication.mContext.getSystemService(Context.TELEPHONY_SERVICE);
        return mTm.getSubscriberId();
    }
 
    /**
     * @Description: 获取手机屏幕宽高
     */
    @SuppressLint("NewApi")
    public static Point getDeviceSize() {
        Point deviceSize = null;
        if (deviceSize == null) {
            deviceSize = new Point(0, 0);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
                ((WindowManager) MApplication.mContext
                        .getSystemService(Context.WINDOW_SERVICE))
                        .getDefaultDisplay().getSize(deviceSize);
            } else {
                Display display = ((WindowManager) MApplication.mContext.getSystemService(Context.WINDOW_SERVICE))
                        .getDefaultDisplay();
                deviceSize.x = display.getWidth();
                deviceSize.y = display.getHeight();
                display = null;
            }
        }
        return deviceSize;
    }
 
    /**
     * 获取Android设备的唯一标识字符串
     * 
     * @param
     * @return
     */
    public static String getDeviceUniqueId() {
        String uniqueId = "";
        try {
            // 3、获取imei
            TelephonyManager telephonyMgr = (TelephonyManager) MApplication.mContext
                    .getSystemService(Context.TELEPHONY_SERVICE);
            uniqueId = telephonyMgr.getDeviceId();
            if (TextUtils.isEmpty(uniqueId)) {
                uniqueId = getDevUUID(MApplication.mContext);
            }
        }catch (Exception e){
            uniqueId=getDevUUID(MApplication.mContext);
        }
 
 
        // // 1、获取mac地址
        // WifiManager wifiMgr = (WifiManager) LApplication.getInstance()
        // .getContext().getSystemService(Context.WIFI_SERVICE);
        // WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
        // if (wifiInfo != null) {
        // uniqueId = wifiInfo.getMacAddress();
        // }
        // if (!TextUtils.isEmpty(uniqueId)) {
        // return uniqueId;
        // }
        //
        // // 2、获取android_id
        // uniqueId = Secure.getString(LApplication.getInstance().getContext()
        // .getContentResolver(), Secure.ANDROID_ID);
        // if (!TextUtils.isEmpty(uniqueId)) {
        // return uniqueId;
        // }
 
        return uniqueId;
    }
 
    public static String getDevUUID(Context mContext) {
        /*TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
        String imei = telephonyManager.getDeviceId();
        String simNo = telephonyManager.getSimSerialNumber();
 
        WifiManager wm = (WifiManager) LApplication
                .getInstance().getContext()
                .getSystemService(Context.WIFI_SERVICE);
        String wifiAddress = wm.getConnectionInfo().getMacAddress();
        */
        String uniqueId="866102023684372";
        try {
            String androidId = "" + android.provider.Settings.Secure.getString(mContext.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
            String ints="";
            for (int i = 0; i < androidId.length(); i++) {
                ints+=formatting(androidId.substring(i, i + 1));
            }
            if(ints.length()>=15){
                ints=ints.substring(0,15);
                uniqueId = ints;
            }
        }catch (Exception e){
            int i=0;
        }
        return uniqueId;
    }
 
    public static String formatting(String a) {
        int chr=a.charAt(0);
        if(chr>47 && chr<58){
            return a;
        }
        int i = 0;
 
        if (a.equals("a")) {
            i = 0;
        }else if (a.equals("b")) {
            i = 1;
        }else if (a.equals("c")) {
            i = 2;
        }else if (a.equals("d")) {
            i = 3;
        }else if (a.equals("e")) {
            i = 4;
        }else if (a.equals("f")) {
            i = 5;
        }
        return i+"";
    }
 
    public static String getAndroidId(){
        try {
            return Settings.Secure.getString(MApplication.mContext.getContentResolver(), Settings.Secure.ANDROID_ID);
        }catch (Exception e){
            return "";
        }
    }
 
    /**
     * 
     * Description:获取运营商名称
     * 
     * @return
     */
    public static String getProvidersName() {
        String ProvidersName = "";
        try {
            TelephonyManager telephonyManager = (TelephonyManager) MApplication.mContext
                    .getSystemService(Context.TELEPHONY_SERVICE);
            // 返回唯一的用户ID;就是这张卡的编号神马的
            String IMSI = telephonyManager.getSubscriberId();
            // IMSI号前面3位460是国家,紧接着后面2位00 02是中国移动,01是中国联通,03是中国电信。
            if (!TextUtils.isEmpty(IMSI)) {
                if (IMSI.startsWith("46000") || IMSI.startsWith("46002")) {
                    ProvidersName = "中国移动";
                } else if (IMSI.startsWith("46001")) {
                    ProvidersName = "中国联通";
                } else if (IMSI.startsWith("46003")) {
                    ProvidersName = "中国电信";
                }
            }
        }catch (Exception e){
 
        }
        return ProvidersName;
    }
 
    /**
     * 获取厂商
     * 
     * @return
     */
    public static String getManufacturer() {
        return android.os.Build.MANUFACTURER; // 厂商
    }
 
    /**
     * 获取手机型号
     * 
     * @return
     */
    public static String getMobileType() {
        return android.os.Build.MODEL; // 手机型号
    }
 
    /**
     * 获取系统发布版本号
     * 
     * @return
     */
 
    public static String getVersionRelease() {
        return android.os.Build.VERSION.RELEASE;
    }
 
    /**
     * 终端设备编码
     */
    public static final String TAG_END_FROM = "Android";
 
}