|
@@ -13,6 +13,7 @@ import android.net.wifi.WifiInfo;
|
13
|
13
|
import android.net.wifi.WifiManager;
|
14
|
14
|
import android.os.Build;
|
15
|
15
|
import android.os.Environment;
|
|
16
|
+import android.os.storage.StorageManager;
|
16
|
17
|
import android.provider.Settings;
|
17
|
18
|
import android.telephony.SubscriptionInfo;
|
18
|
19
|
import android.telephony.SubscriptionManager;
|
|
@@ -21,7 +22,11 @@ import android.text.TextUtils;
|
21
|
22
|
import androidx.core.app.ActivityCompat;
|
22
|
23
|
|
23
|
24
|
import java.io.File;
|
|
25
|
+import java.lang.reflect.Array;
|
|
26
|
+import java.lang.reflect.InvocationTargetException;
|
24
|
27
|
import java.lang.reflect.Method;
|
|
28
|
+import java.math.BigDecimal;
|
|
29
|
+import java.math.RoundingMode;
|
25
|
30
|
import java.util.ArrayList;
|
26
|
31
|
import java.util.List;
|
27
|
32
|
import java.util.Locale;
|
|
@@ -342,13 +347,55 @@ public class SystemUtil {
|
342
|
347
|
|
343
|
348
|
public static boolean isSDCardMounted(Context context) {
|
344
|
349
|
try{
|
345
|
|
- File[] externalFilesDirs = context.getExternalFilesDirs(null);
|
346
|
|
- return externalFilesDirs.length > 1;
|
|
350
|
+ /* File[] externalFilesDirs = context.getExternalFilesDirs(null);
|
|
351
|
+ return externalFilesDirs.length > 1;*/
|
|
352
|
+ /* String state = Environment.getExternalStorageState();
|
|
353
|
+ return Environment.MEDIA_MOUNTED.equals(state);*/
|
|
354
|
+ return IsExistCard(context);
|
347
|
355
|
}catch (Exception e){
|
348
|
356
|
return false;
|
349
|
357
|
}
|
350
|
358
|
}
|
351
|
359
|
|
|
360
|
+ /**
|
|
361
|
+ * 判断外置SD/TF卡是否挂载
|
|
362
|
+ *
|
|
363
|
+ * @return
|
|
364
|
+ */
|
|
365
|
+ public static boolean IsExistCard(Context context) {
|
|
366
|
+ boolean result = false;
|
|
367
|
+ try {
|
|
368
|
+ StorageManager mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
|
|
369
|
+ Class<?> storageVolumeClazz = null;
|
|
370
|
+ storageVolumeClazz = Class.forName("android.os.storage.StorageVolume");
|
|
371
|
+ Method getVolumeList = mStorageManager.getClass().getMethod("getVolumeList");
|
|
372
|
+ Method getPath = storageVolumeClazz.getMethod("getPath");
|
|
373
|
+ Method isRemovable = storageVolumeClazz.getMethod("isRemovable");
|
|
374
|
+ Method getState = storageVolumeClazz.getMethod("getState");
|
|
375
|
+ Object obj = null;
|
|
376
|
+ try {
|
|
377
|
+ obj = getVolumeList.invoke(mStorageManager);
|
|
378
|
+ } catch (InvocationTargetException e) {
|
|
379
|
+ e.printStackTrace();
|
|
380
|
+ }
|
|
381
|
+ final int length = Array.getLength(obj);
|
|
382
|
+ for (int i = 0; i < length; i++) {
|
|
383
|
+ Object storageVolumeElement = Array.get(obj, i);
|
|
384
|
+ String path = (String) getPath.invoke(storageVolumeElement);
|
|
385
|
+ boolean removable = (Boolean) isRemovable.invoke(storageVolumeElement);
|
|
386
|
+ LogUtils.d("sd卡可移动"+removable);
|
|
387
|
+ String state = (String) getState.invoke(storageVolumeElement);
|
|
388
|
+ if (removable && state.equals(Environment.MEDIA_MOUNTED)) {
|
|
389
|
+ result = true;
|
|
390
|
+ break;
|
|
391
|
+ }
|
|
392
|
+ }
|
|
393
|
+ } catch (Exception e) {
|
|
394
|
+ e.printStackTrace();
|
|
395
|
+ }
|
|
396
|
+ return result;
|
|
397
|
+ }
|
|
398
|
+
|
352
|
399
|
public static String getProcessName(Context cxt, int pid) {
|
353
|
400
|
//获取ActivityManager对象
|
354
|
401
|
ActivityManager am = (ActivityManager) cxt.getSystemService(Context.ACTIVITY_SERVICE);
|
|
@@ -365,4 +412,32 @@ public class SystemUtil {
|
365
|
412
|
return null;
|
366
|
413
|
}
|
367
|
414
|
|
|
415
|
+ //计算经纬度距离
|
|
416
|
+ public static double distance(double lat1, double lon1, double lat2, double lon2) {
|
|
417
|
+ // 将经纬度从度转换为弧度
|
|
418
|
+ double lat1Rad = Math.toRadians(lat1);
|
|
419
|
+ double lon1Rad = Math.toRadians(lon1);
|
|
420
|
+ double lat2Rad = Math.toRadians(lat2);
|
|
421
|
+ double lon2Rad = Math.toRadians(lon2);
|
|
422
|
+
|
|
423
|
+ // 地球半径
|
|
424
|
+ double earthRadius = 6371.0; // 千米
|
|
425
|
+
|
|
426
|
+ // 计算经纬度差
|
|
427
|
+ double deltaLat = lat2Rad - lat1Rad;
|
|
428
|
+ double deltaLon = lon2Rad - lon1Rad;
|
|
429
|
+
|
|
430
|
+ // 使用Haversine公式计算距离
|
|
431
|
+ double a = Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2) +
|
|
432
|
+ Math.cos(lat1Rad) * Math.cos(lat2Rad) *
|
|
433
|
+ Math.sin(deltaLon / 2) * Math.sin(deltaLon / 2);
|
|
434
|
+ double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
435
|
+ double distanceRad = earthRadius * c;
|
|
436
|
+
|
|
437
|
+ // 将弧度转换回千米,并保留两位小数
|
|
438
|
+ double distanceKm = distanceRad;
|
|
439
|
+ BigDecimal roundedDistance = new BigDecimal(distanceKm).setScale(4, RoundingMode.HALF_UP);
|
|
440
|
+
|
|
441
|
+ return roundedDistance.doubleValue();
|
|
442
|
+ }
|
368
|
443
|
}
|