|
@@ -1,13 +1,21 @@
|
1
|
1
|
package com.xhly.corelib.utils;
|
2
|
2
|
|
|
3
|
+import android.Manifest;
|
3
|
4
|
import android.bluetooth.BluetoothAdapter;
|
4
|
5
|
import android.content.Context;
|
|
6
|
+import android.content.pm.PackageManager;
|
|
7
|
+import android.location.Criteria;
|
|
8
|
+import android.location.Location;
|
|
9
|
+import android.location.LocationManager;
|
5
|
10
|
import android.net.wifi.WifiInfo;
|
6
|
11
|
import android.net.wifi.WifiManager;
|
7
|
12
|
import android.os.Build;
|
8
|
13
|
import android.telephony.SubscriptionInfo;
|
9
|
14
|
import android.telephony.SubscriptionManager;
|
10
|
15
|
import android.text.TextUtils;
|
|
16
|
+import android.util.Log;
|
|
17
|
+
|
|
18
|
+import androidx.core.app.ActivityCompat;
|
11
|
19
|
|
12
|
20
|
import java.io.File;
|
13
|
21
|
import java.lang.reflect.Method;
|
|
@@ -173,7 +181,7 @@ public class SystemUtil {
|
173
|
181
|
|
174
|
182
|
public static String getICCID(Context context) {
|
175
|
183
|
String iccid = "";
|
176
|
|
- try{
|
|
184
|
+ try {
|
177
|
185
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP_MR1) {
|
178
|
186
|
SubscriptionManager sm = SubscriptionManager.from(context);
|
179
|
187
|
List<SubscriptionInfo> sis = sm.getActiveSubscriptionInfoList();
|
|
@@ -181,49 +189,83 @@ public class SystemUtil {
|
181
|
189
|
SubscriptionInfo si1 = sis.get(0);
|
182
|
190
|
String iccId1 = si1.getIccId();
|
183
|
191
|
String phoneNum1 = si1.getNumber();
|
184
|
|
- iccid=iccId1;
|
185
|
|
- LogUtils.d("获得手机信息","问题是mei偶222尔与哦是的"+phoneNum1);
|
|
192
|
+ iccid = iccId1;
|
|
193
|
+ LogUtils.d("获得手机信息", "问题是mei偶222尔与哦是的" + phoneNum1);
|
186
|
194
|
}
|
187
|
195
|
if (sis.size() >= 2) {
|
188
|
196
|
SubscriptionInfo si2 = sis.get(1);
|
189
|
197
|
String iccId2 = si2.getIccId();
|
190
|
198
|
String phoneNum2 = si2.getNumber();
|
191
|
|
- iccid=iccId2;
|
192
|
|
- LogUtils.d("获得手机信息","问题是mei偶尔与哦是的"+si2.toString());
|
|
199
|
+ iccid = iccId2;
|
|
200
|
+ LogUtils.d("获得手机信息", "问题是mei偶尔与哦是的" + si2.toString());
|
193
|
201
|
}
|
194
|
202
|
// 获取SIM卡数量相关信息:
|
195
|
203
|
int count = sm.getActiveSubscriptionInfoCount();//当前实际插卡数量
|
196
|
204
|
int max = sm.getActiveSubscriptionInfoCountMax();//当前卡槽数量
|
197
|
205
|
}
|
198
|
|
- }catch (Exception e){
|
199
|
|
- LogUtils.d("获得手机信息","问题是"+e.toString());
|
|
206
|
+ } catch (Exception e) {
|
|
207
|
+ LogUtils.d("获得手机信息", "问题是" + e.toString());
|
200
|
208
|
}
|
201
|
209
|
return iccid;
|
202
|
210
|
}
|
203
|
211
|
|
204
|
|
- public static String getWifiMac(Context context){
|
205
|
|
- String wifiMac="";
|
|
212
|
+ public static String getWifiMac(Context context) {
|
|
213
|
+ String wifiMac = "";
|
206
|
214
|
try {
|
207
|
215
|
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
208
|
216
|
WifiInfo connectionInfo = wifiManager.getConnectionInfo();
|
209
|
217
|
wifiMac = connectionInfo.getMacAddress();
|
210
|
|
- }catch (Exception e){
|
211
|
|
- LogUtils.d("获得手机信息","wifi问题是"+e.toString());
|
|
218
|
+ } catch (Exception e) {
|
|
219
|
+ LogUtils.d("获得手机信息", "wifi问题是" + e.toString());
|
212
|
220
|
}
|
213
|
221
|
return wifiMac;
|
214
|
|
- }
|
|
222
|
+ }
|
215
|
223
|
|
216
|
|
- public static String getBluetoothMac(){
|
217
|
|
- String bMac="";
|
218
|
|
- try{
|
219
|
|
- BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();
|
|
224
|
+ public static String getBluetoothMac() {
|
|
225
|
+ String bMac = "";
|
|
226
|
+ try {
|
|
227
|
+ BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();
|
220
|
228
|
/* if (defaultAdapter.isEnabled()){
|
221
|
229
|
bMac= defaultAdapter.getAddress();
|
222
|
230
|
}*/
|
223
|
|
- bMac= defaultAdapter.getAddress();
|
224
|
|
- }catch (Exception e){
|
225
|
|
- LogUtils.d("获得手机信息","bluetooth问题是"+e.toString());
|
226
|
|
- }
|
227
|
|
- return bMac;
|
228
|
|
- }
|
|
231
|
+ bMac = defaultAdapter.getAddress();
|
|
232
|
+ } catch (Exception e) {
|
|
233
|
+ LogUtils.d("获得手机信息", "bluetooth问题是" + e.toString());
|
|
234
|
+ }
|
|
235
|
+ return bMac;
|
|
236
|
+ }
|
|
237
|
+
|
|
238
|
+ public static Location getLocation(Context context) {
|
|
239
|
+ Location data=null;
|
|
240
|
+ try {
|
|
241
|
+ String locationProvider = "";
|
|
242
|
+ LocationManager systemService = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
|
243
|
+ List<String> providers = systemService.getProviders(true);
|
|
244
|
+ if (providers.contains(LocationManager.GPS_PROVIDER)) {
|
|
245
|
+ locationProvider = LocationManager.GPS_PROVIDER;
|
|
246
|
+ } else if (providers.contains(LocationManager.NETWORK_PROVIDER)) {
|
|
247
|
+ locationProvider = LocationManager.NETWORK_PROVIDER;
|
|
248
|
+ } else {
|
|
249
|
+ return data;
|
|
250
|
+ }
|
|
251
|
+ Criteria criteria=new Criteria();
|
|
252
|
+ criteria.setAltitudeRequired(false);
|
|
253
|
+ criteria.setBearingRequired(false);
|
|
254
|
+ criteria.setAccuracy(Criteria.ACCURACY_FINE);
|
|
255
|
+ criteria.setCostAllowed(true);
|
|
256
|
+ String bestProvider = systemService.getBestProvider(criteria, true);
|
|
257
|
+ if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED &&
|
|
258
|
+ ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
|
|
259
|
+ data = systemService.getLastKnownLocation(bestProvider);
|
|
260
|
+ if (data!=null){
|
|
261
|
+ LogUtils.d("获得地理位置","经度"+data.getLongitude()+"|||维度=="+data.getLatitude());
|
|
262
|
+ }else {
|
|
263
|
+ LogUtils.d("获得地理位置","没有地址");
|
|
264
|
+ }
|
|
265
|
+ }
|
|
266
|
+ } catch (Exception e) {
|
|
267
|
+ LogUtils.d("获得地理位置","失败原因"+e.toString());
|
|
268
|
+ }
|
|
269
|
+ return data;
|
|
270
|
+ }
|
229
|
271
|
}
|