Bläddra i källkod

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

master
wangwanlei 11 månader sedan
förälder
incheckning
b3f5b4c598

+ 14
- 7
app/src/main/AndroidManifest.xml Visa fil

@@ -29,8 +29,8 @@
29 29
         android:fullBackupContent="@xml/backup_rules"
30 30
         android:icon="@mipmap/ic_launcher"
31 31
         android:label="@string/app_name"
32
-        android:roundIcon="@mipmap/ic_launcher_round"
33 32
         android:networkSecurityConfig="@xml/network_security_config"
33
+        android:roundIcon="@mipmap/ic_launcher_round"
34 34
         android:supportsRtl="true"
35 35
         android:theme="@style/MyStyle"
36 36
         tools:targetApi="31">
@@ -60,15 +60,14 @@
60 60
             android:name=".ui.login.activity.LoginActivity"
61 61
             android:launchMode="singleTask"
62 62
             android:screenOrientation="landscape"
63
-            android:windowSoftInputMode="adjustResize"
64
-            />
63
+            android:windowSoftInputMode="adjustResize" />
65 64
 
66 65
         <receiver
67 66
             android:name=".broadcastreceiver.XhlyBroadCastReceiver"
68 67
             android:enabled="true"
69 68
             android:exported="true">
70 69
             <intent-filter>
71
-               <!-- <action android:name="com.linspirer.edu.loginapkfinish" /-->
70
+                <!-- <action android:name="com.linspirer.edu.loginapkfinish" /-->
72 71
                 <action android:name="test" />
73 72
             </intent-filter>
74 73
         </receiver>
@@ -90,6 +89,14 @@
90 89
                 <action android:name="android.bluetooth.BluetoothAdapter.STATE_ON" />
91 90
             </intent-filter>
92 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 100
         <!--     &lt;!&ndash;覆盖安装清理数据广播——————————————————————————————————————————————————————————&ndash;&gt;
94 101
              <receiver
95 102
                  android:name=".broadcastreceiver.AppInstallReceiver"
@@ -117,9 +124,9 @@
117 124
                 android:name="android.accessibilityservice"
118 125
                 android:resource="@xml/accessibility_service_config" />
119 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 131
         <provider
125 132
             android:name="androidx.core.content.FileProvider"

+ 50
- 0
app/src/main/java/com/xhly/manageapp/broadcastreceiver/SimStateReceive.java Visa fil

@@ -0,0 +1,50 @@
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
+}

Laddar…
Avbryt
Spara