Browse Source

1.添加Sd卡插拔状态广播

master
wangwanlei 11 months ago
parent
commit
0dcbf3e2a4

+ 11
- 0
app/src/main/AndroidManifest.xml View File

@@ -97,6 +97,17 @@
97 97
                 <action android:name="android.intent.action.SIM_STATE_CHANGED" />
98 98
             </intent-filter>
99 99
         </receiver>
100
+        <receiver
101
+            android:name="com.xhly.manageapp.broadcastreceiver.SDReceiver"
102
+            android:enabled="true"
103
+            android:exported="true">
104
+            <intent-filter android:priority="1000">
105
+                <action android:name="android.intent.action.MEDIA_CHECKING" />
106
+                <action android:name="android.intent.action.MEDIA_MOUNTED" />
107
+                <action android:name="android.intent.action.MEDIA_EJECT" />
108
+                <action android:name="android.intent.action.MEDIA_UNMOUNTED" />
109
+            </intent-filter>
110
+        </receiver>
100 111
         <!--     &lt;!&ndash;覆盖安装清理数据广播——————————————————————————————————————————————————————————&ndash;&gt;
101 112
              <receiver
102 113
                  android:name=".broadcastreceiver.AppInstallReceiver"

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

@@ -0,0 +1,28 @@
1
+package com.xhly.manageapp.broadcastreceiver
2
+
3
+import android.content.BroadcastReceiver
4
+import android.content.Context
5
+import android.content.Intent
6
+
7
+class SDReceiver: BroadcastReceiver() {
8
+    override fun onReceive(context: Context, intent: Intent) {
9
+        val action = intent.action
10
+        when (action) {
11
+            Intent.ACTION_MEDIA_CHECKING->
12
+            {
13
+                //SD卡正在检查
14
+            }
15
+             Intent.ACTION_MEDIA_MOUNTED->
16
+             {
17
+                 //SD卡挂载成功
18
+             }
19
+            Intent.ACTION_MEDIA_EJECT->{
20
+                //SD卡拔出
21
+
22
+            }
23
+            Intent.ACTION_MEDIA_UNMOUNTED->{
24
+                //SD卡卸载成功
25
+            }
26
+        }
27
+    }
28
+}

Loading…
Cancel
Save