在荣耀50上使用Scan Kit时应用程序崩溃
App crash when using Scan Kit on Honor 50
我正在使用 com.huawei.hms:scan:1.3.2.300
设备:Honor 50,Magic UI 4.2,Android 版本 11。
以下是崩溃日志:
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)
请帮忙。
如果SDK版本高于或等于AndroidR,需要在代码中动态申请READ_PHONE_STATE
权限。请检查并重试。
权限代码如下:
@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);
}
}
我正在使用 com.huawei.hms:scan:1.3.2.300
设备:Honor 50,Magic UI 4.2,Android 版本 11。
以下是崩溃日志:
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)
请帮忙。
如果SDK版本高于或等于AndroidR,需要在代码中动态申请READ_PHONE_STATE
权限。请检查并重试。
权限代码如下:
@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);
}
}