项目适配Android9.0+出现的问题及解决
- 关于
-
- Java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/conn/scheme/SchemeRegistry
- The user 10154 does not meet the requirements to access device identifiers.
- startForeground requires android.permission.FOREGROUND_SERVICE
- (xxxx.server)' ~ Channel is unrecoverably broken and will be disposed!
- No implementation found for int com.baidu.platform.comjni.tools.JNITools.initClass
- Android9.0明文访问
- Android10+权限的申请问题
- Android10+存储域变化
关于
项目大概用到了百度地图sdk、定位权限、前后台服务等。
主要涉及的权限有网络权限、定位权限(包括后台定位)、存储权限。
项目的build版本 3.5.3
targetSdkVersion 29
其实一些9.0+的问题也适配到了
Java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/conn/scheme/SchemeRegistry
这个在9.0以上运行闪退会报上面这个错误,解决办法:
在AndroidManifest.xml文件的application标签里面加入如下:
<application...>
//加入如下
<uses-library android:name="org.apache.http.legacy" android:required="false" />
</application>
The user 10154 does not meet the requirements to access device identifiers.
首先看一下我的错误代码:
/**
* 获取设备编号(对于GSM手机为IMEI;对于CDMA手机为MEID;不支持为null),需要权限android.permission.READ_PHONE_STATE
*/
@SuppressLint({
"MissingPermission", "HardwareIds"})
public static String getDeviceId(Context context) {
TelephonyManager telephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return telephonyMgr.getDeviceId() == null ? "" : telephonyMgr.getDeviceId();
}
String deviceCode = DeviceUtils.getDeviceId(getContext());
这里通过代码获取硬件标识符。
解释一下:自 Android 10(API 级别 29)起,您的应用必须是设备或个人资料所有者应用,具有特殊运营商许可,或具有 READ_PRIVILEGED_PHONE_STATE 特权,才能访问不可重置的设备标识符
这个是运行在Android10及以上会出现的闪退问题,解决办法:
- 第一种,降低当前的targetSdkVersion,使其低于29(这显然和我写这篇文章的初心不符)
- 第二种,就是加一个判断啦,如下:
private String deviceCode;
if (Build.VERSION<