Pārlūkot izejas kodu

1.添加SIM卡号码读取功能。

20241218TB223FC(测试jar包)
wangwanlei pirms 8 mēnešiem
vecāks
revīzija
36091c185f

+ 1
- 0
app/src/main/AndroidManifest.xml Parādīt failu

@@ -9,6 +9,7 @@
9 9
         android:name="android.permission.QUERY_ALL_PACKAGES"
10 10
         tools:ignore="QueryAllPackagesPermission" />
11 11
     <uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" />
12
+    <uses-permission android:name="android.permission.READ_PHONE_NUMBERS"/>
12 13
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
13 14
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
14 15
     <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" />

+ 1
- 1
app/src/main/java/com/xhly/manageapp/ui/login/activity/LoginActivity.kt Parādīt failu

@@ -113,7 +113,7 @@ class LoginActivity : BaseActivity<LoginViewModel, ActivityLoginBinding>() {
113 113
         mBinding.loginBtn.setOnClickListener {
114 114
             val rxPermissions = RxPermissions(this)
115 115
             //有无权限都要登录
116
-            val request = rxPermissions.request(Manifest.permission.READ_PHONE_STATE)
116
+            val request = rxPermissions.request(Manifest.permission.READ_PHONE_STATE,Manifest.permission.READ_PHONE_NUMBERS)
117 117
             request.subscribe({
118 118
                 login()
119 119
             },{

+ 27
- 0
corelib/src/main/java/com/xhly/corelib/utils/SystemUtil.java Parādīt failu

@@ -22,6 +22,7 @@ import androidx.core.app.ActivityCompat;
22 22
 
23 23
 import java.io.File;
24 24
 import java.lang.reflect.Method;
25
+import java.util.ArrayList;
25 26
 import java.util.List;
26 27
 import java.util.Locale;
27 28
 
@@ -236,6 +237,32 @@ public class SystemUtil {
236 237
         return iccid;
237 238
     }
238 239
 
240
+    public static ArrayList<String> getPhoneNumber(Context context) {
241
+        ArrayList<String> numList = new ArrayList<String>();
242
+        try {
243
+            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP_MR1) {
244
+                SubscriptionManager sm = SubscriptionManager.from(context);
245
+                List<SubscriptionInfo> sis = sm.getActiveSubscriptionInfoList();
246
+                if (sis.size() >= 1) {
247
+                    SubscriptionInfo si1 = sis.get(0);
248
+                    String phoneNum1 = si1.getNumber();
249
+                    numList.add(phoneNum1);
250
+                }
251
+                if (sis.size() >= 2) {
252
+                    SubscriptionInfo si2 = sis.get(1);
253
+                    String phoneNum2 = si2.getNumber();
254
+                    numList.add(phoneNum2);
255
+                }
256
+                // 获取SIM卡数量相关信息:
257
+                int count = sm.getActiveSubscriptionInfoCount();//当前实际插卡数量
258
+                int max = sm.getActiveSubscriptionInfoCountMax();//当前卡槽数量
259
+            }
260
+        } catch (Exception e) {
261
+            LogUtils.d("获得手机信息", "问题是" + e.toString());
262
+        }
263
+        return numList;
264
+    }
265
+
239 266
     public static String getWifiMac(Context context) {
240 267
         String wifiMac = "";
241 268
         try {

Notiek ielāde…
Atcelt
Saglabāt