Browse Source

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

20241218TB223FC(测试jar包)
wangwanlei 8 months ago
parent
commit
59896cb0f9

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

22
              Intent.ACTION_MEDIA_MOUNTED->
22
              Intent.ACTION_MEDIA_MOUNTED->
23
              {
23
              {
24
                  //SD卡挂载成功,可能会发送两次
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
                      installLastTime=System.currentTimeMillis()
26
                      installLastTime=System.currentTimeMillis()
27
                      LogShow("sd卡已插入")
27
                      LogShow("sd卡已插入")
28
                      UIEvent(Const.SDINSTALL).post()
28
                      UIEvent(Const.SDINSTALL).post()
37
             }
37
             }
38
             Intent.ACTION_MEDIA_UNMOUNTED->{
38
             Intent.ACTION_MEDIA_UNMOUNTED->{
39
                 //SD卡卸载成功
39
                 //SD卡卸载成功
40
+                LogShow("sd卡卸载成功")
40
             }
41
             }
41
         }
42
         }
42
     }
43
     }

+ 6
- 6
corelib/src/main/java/com/xhly/corelib/utils/SystemUtil.java View File

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

Loading…
Cancel
Save