Explorar el Código

1.优化sd卡插入状态判断。

20241218TB223FC(测试jar包)
wangwanlei hace 8 meses
padre
commit
59896cb0f9

+ 2
- 1
app/src/main/java/com/xhly/manageapp/broadcastreceiver/SDReceiver.kt Ver fichero

@@ -22,7 +22,7 @@ class SDReceiver: BroadcastReceiver() {
22 22
              Intent.ACTION_MEDIA_MOUNTED->
23 23
              {
24 24
                  //SD卡挂载成功,可能会发送两次
25
-                 if ((installLastTime==0L||(System.currentTimeMillis()- installLastTime>1000))&&SystemUtil.isSDCardMounted(context)){
25
+                 if ((installLastTime==0L||(System.currentTimeMillis()- installLastTime>1000))&&SystemUtil.isSDCardMounted(context,true)){
26 26
                      installLastTime=System.currentTimeMillis()
27 27
                      LogShow("sd卡已插入")
28 28
                      UIEvent(Const.SDINSTALL).post()
@@ -37,6 +37,7 @@ class SDReceiver: BroadcastReceiver() {
37 37
             }
38 38
             Intent.ACTION_MEDIA_UNMOUNTED->{
39 39
                 //SD卡卸载成功
40
+                LogShow("sd卡卸载成功")
40 41
             }
41 42
         }
42 43
     }

+ 6
- 6
corelib/src/main/java/com/xhly/corelib/utils/SystemUtil.java Ver fichero

@@ -345,24 +345,24 @@ public class SystemUtil {
345 345
         }
346 346
     }
347 347
 
348
-    public static boolean isSDCardMounted(Context context) {
348
+    public static boolean isSDCardMounted(Context context,boolean stateFlag) {
349 349
         try{
350 350
           /*  File[] externalFilesDirs = context.getExternalFilesDirs(null);
351 351
             return externalFilesDirs.length > 1;*/
352 352
          /*   String state = Environment.getExternalStorageState();
353 353
             return Environment.MEDIA_MOUNTED.equals(state);*/
354
-           return IsExistCard(context);
354
+           return IsExistCard(context,stateFlag);
355 355
         }catch (Exception e){
356 356
             return false;
357 357
         }
358 358
     }
359 359
 
360 360
     /**
361
-     * 判断外置SD/TF卡是否挂载
361
+     * 判断外置SD/TF卡是否挂载 stateFlag表示外部传入的挂载状态,用于处理sd卡被系统禁用时的状态判断情况
362 362
      *
363 363
      * @return
364 364
      */
365
-    public static boolean IsExistCard(Context context) {
365
+    public static boolean IsExistCard(Context context,boolean stateFlag) {
366 366
         boolean result = false;
367 367
         try {
368 368
             StorageManager mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
@@ -383,9 +383,9 @@ public class SystemUtil {
383 383
                 Object storageVolumeElement = Array.get(obj, i);
384 384
                 String path = (String) getPath.invoke(storageVolumeElement);
385 385
                 boolean removable = (Boolean) isRemovable.invoke(storageVolumeElement);
386
-                LogUtils.d("sd卡可移动"+removable);
387 386
                 String state = (String) getState.invoke(storageVolumeElement);
388
-                if (removable && state.equals(Environment.MEDIA_MOUNTED)) {
387
+                LogUtils.d("sd卡可移动"+removable+"|||"+state);
388
+                if (removable && (state.equals(Environment.MEDIA_MOUNTED)||stateFlag)) {
389 389
                     result = true;
390 390
                     break;
391 391
                 }

Loading…
Cancelar
Guardar