Browse Source

1.添加Sim卡状态变动广播

master
wangwanlei 11 months ago
parent
commit
b3f5b4c598

+ 14
- 7
app/src/main/AndroidManifest.xml View File

29
         android:fullBackupContent="@xml/backup_rules"
29
         android:fullBackupContent="@xml/backup_rules"
30
         android:icon="@mipmap/ic_launcher"
30
         android:icon="@mipmap/ic_launcher"
31
         android:label="@string/app_name"
31
         android:label="@string/app_name"
32
-        android:roundIcon="@mipmap/ic_launcher_round"
33
         android:networkSecurityConfig="@xml/network_security_config"
32
         android:networkSecurityConfig="@xml/network_security_config"
33
+        android:roundIcon="@mipmap/ic_launcher_round"
34
         android:supportsRtl="true"
34
         android:supportsRtl="true"
35
         android:theme="@style/MyStyle"
35
         android:theme="@style/MyStyle"
36
         tools:targetApi="31">
36
         tools:targetApi="31">
60
             android:name=".ui.login.activity.LoginActivity"
60
             android:name=".ui.login.activity.LoginActivity"
61
             android:launchMode="singleTask"
61
             android:launchMode="singleTask"
62
             android:screenOrientation="landscape"
62
             android:screenOrientation="landscape"
63
-            android:windowSoftInputMode="adjustResize"
64
-            />
63
+            android:windowSoftInputMode="adjustResize" />
65
 
64
 
66
         <receiver
65
         <receiver
67
             android:name=".broadcastreceiver.XhlyBroadCastReceiver"
66
             android:name=".broadcastreceiver.XhlyBroadCastReceiver"
68
             android:enabled="true"
67
             android:enabled="true"
69
             android:exported="true">
68
             android:exported="true">
70
             <intent-filter>
69
             <intent-filter>
71
-               <!-- <action android:name="com.linspirer.edu.loginapkfinish" /-->
70
+                <!-- <action android:name="com.linspirer.edu.loginapkfinish" /-->
72
                 <action android:name="test" />
71
                 <action android:name="test" />
73
             </intent-filter>
72
             </intent-filter>
74
         </receiver>
73
         </receiver>
90
                 <action android:name="android.bluetooth.BluetoothAdapter.STATE_ON" />
89
                 <action android:name="android.bluetooth.BluetoothAdapter.STATE_ON" />
91
             </intent-filter>
90
             </intent-filter>
92
         </receiver>
91
         </receiver>
92
+        <receiver
93
+            android:name="com.xhly.manageapp.broadcastreceiver.SimStateReceive"
94
+            android:enabled="true"
95
+            android:exported="true">
96
+            <intent-filter android:priority="1000">
97
+                <action android:name="android.intent.action.SIM_STATE_CHANGED" />
98
+            </intent-filter>
99
+        </receiver>
93
         <!--     &lt;!&ndash;覆盖安装清理数据广播——————————————————————————————————————————————————————————&ndash;&gt;
100
         <!--     &lt;!&ndash;覆盖安装清理数据广播——————————————————————————————————————————————————————————&ndash;&gt;
94
              <receiver
101
              <receiver
95
                  android:name=".broadcastreceiver.AppInstallReceiver"
102
                  android:name=".broadcastreceiver.AppInstallReceiver"
117
                 android:name="android.accessibilityservice"
124
                 android:name="android.accessibilityservice"
118
                 android:resource="@xml/accessibility_service_config" />
125
                 android:resource="@xml/accessibility_service_config" />
119
         </service>
126
         </service>
120
-        <service android:name="com.xhly.manageapp.service.websocket.AppSocketService"
121
-            android:foregroundServiceType="dataSync"
122
-            />
127
+        <service
128
+            android:name="com.xhly.manageapp.service.websocket.AppSocketService"
129
+            android:foregroundServiceType="dataSync" />
123
 
130
 
124
         <provider
131
         <provider
125
             android:name="androidx.core.content.FileProvider"
132
             android:name="androidx.core.content.FileProvider"

+ 50
- 0
app/src/main/java/com/xhly/manageapp/broadcastreceiver/SimStateReceive.java View File

1
+package com.xhly.manageapp.broadcastreceiver;
2
+
3
+import android.app.Service;
4
+import android.content.BroadcastReceiver;
5
+import android.content.Context;
6
+import android.content.Intent;
7
+import android.telephony.TelephonyManager;
8
+
9
+import java.util.Objects;
10
+
11
+public class SimStateReceive extends BroadcastReceiver {
12
+    private final static String ACTION_SIM_STATE_CHANGED = "android.intent.action.SIM_STATE_CHANGED";
13
+    private final static int SIM_VALID = 0;
14
+    private final static int SIM_INVALID = 1;
15
+    private int simState = SIM_INVALID;
16
+
17
+    public int getSimState() {
18
+        return simState;
19
+    }
20
+
21
+    @Override
22
+    public void onReceive(Context context, Intent intent) {
23
+        System.out.println("sim state changed");
24
+        try {
25
+            if (Objects.equals(intent.getAction(), ACTION_SIM_STATE_CHANGED)) {
26
+                TelephonyManager tm = (TelephonyManager)context.getSystemService(Service.TELEPHONY_SERVICE);
27
+                int state = tm.getSimState();
28
+                switch (state) {
29
+                    case TelephonyManager.SIM_STATE_READY :    //
30
+                        simState = SIM_VALID;
31
+                      /*  Logger.i("有sim卡="+simState);
32
+                        new ReportPhoneNumber().start();*/
33
+                        break;
34
+                    case TelephonyManager.SIM_STATE_UNKNOWN :
35
+                    case TelephonyManager.SIM_STATE_ABSENT :
36
+                    case TelephonyManager.SIM_STATE_PIN_REQUIRED :
37
+                    case TelephonyManager.SIM_STATE_PUK_REQUIRED :
38
+                    case TelephonyManager.SIM_STATE_NETWORK_LOCKED :
39
+                    default:
40
+                        simState = SIM_INVALID;
41
+                      /*  Logger.i("没sim卡="+simState);*/
42
+                        break;
43
+                }
44
+            }
45
+        }catch (Exception e){
46
+            e.printStackTrace();
47
+        }
48
+    }
49
+
50
+}

Loading…
Cancel
Save