Home > Back-end >  App crash when using Scan Kit on Honor 50
App crash when using Scan Kit on Honor 50

Time:11-26

I'm using com.huawei.hms:scan:1.3.2.300

Device: Honor 50, Magic UI 4.2, Android version 11.

The following is the crash log:

java.lang.SecurityException: getNetworkTypeForSubscriber 5 at android.os.Parcel.createExceptionOrNull(Parcel.java:2384) 6 at android.os.Parcel.createException(Parcel.java:2368) 7 at android.os.Parcel.readException(Parcel.java:2351) 8 at android.os.Parcel.readException(Parcel.java:2293) 9 at com.android.internal.telephony.ITelephony$Stub$Proxy.getNetworkTypeForSubscriber(ITelephony.java:8795) 10 at android.telephony.TelephonyManager.getNetworkType(TelephonyManager.java:3102) 11 at android.telephony.TelephonyManager.getNetworkType(TelephonyManager.java:3064) 12 at com.huawei.hms.mlkit.common.ha.d.b(HianalyticsLogUtils.java:68) 13 at com.huawei.hms.mlkit.common.ha.HianalyticsLogProvider.logEnd(HianalyticsLogProvider.java:6315) 14 at com.huawei.hms.ml.camera.g$a.a(HiAnalyticsThread.java:109) 15 at com.huawei.hms.ml.camera.g$a.handleMessage(HiAnalyticsThread.java:78) 16 at android.os.Handler.dispatchMessage(Handler.java:109) 17 at android.os.Looper.loop(Looper.java:228) 18 at com.huawei.hms.ml.camera.g.run(HiAnalyticsThread.java:51)

Please help.

CodePudding user response:

enter image description here

If the SDK version is later than or equal to Android R, you need to apply for READ_PHONE_STATE permissions dynamically in the code. Please check and try again.

The permission code is as follows:

    @Override
    protected void onStart() {
        super.onStart();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {

            int res = checkSelfPermission(android.Manifest.permission.READ_PHONE_STATE);
            if (res != PackageManager.PERMISSION_GRANTED) {
                requestPermissions(new String[]{android.Manifest.permission.READ_PHONE_STATE}, 123);
            }

        }
    }

    private final static int REQUEST_CODE_ASK_PERMISSIONS = 1003;

    @Override
    public void onRequestPermissionsResult(int requestCode,
                                           @NonNull String[] permissions, @NonNull int[] grantResults) {
        switch (requestCode) {
            case REQUEST_CODE_ASK_PERMISSIONS:
                if (grantResults[0] != PackageManager.PERMISSION_GRANTED) {
                    Toast.makeText(getApplicationContext(), "READ_PHONE_STATE Denied", Toast.LENGTH_SHORT)
                            .show();
                } else {
                }
                stepAfterSplash();

                break;
            default:
                super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }

  • Related