安卓系统版本与SDK的对应关系
1、android8.0遇到的问题:
Caused by: java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation
原因:谷歌在安卓8.0版本时为了支持全面屏,增加了限制:如果是透明的Activity,则不能固定它的方向,因为它的方向其实是依赖其父Activity的,因此,只要去掉AndroidManifest文件中"透明的Activity"的固定方向的代码即可
android:screenOrientation="portrait"
2、android8.0遇到的问题:
The SDK platform-tools version (26.0.1) is too old to check APIs compiled with API 28; please update
然后点击File-->Invalidate Caches/Restart重启
3、android8.0自动安装下载好的apk文件,唤醒安装功能失败:只需添加权限
<!-- Android 8.0唤不起系统安装器-->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
4、android9.0异常(兼容http):CLEARTEXT communication ** not permitted by network security policy
解决办法:创建res/xml/network_security_config.xml文件,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
在AndroidManifest.xml下的application标签增加networkSecurityConfig属性配置:
<application
android:networkSecurityConfig="@xml/network_security_config"
>
<!-- -->
</application>
5、Android9.0异常:Error inflating class android.webkit.WebView
解决方法一:AndroidManifest.xml中添加代码(未见效)
<!-- Android 9.0WebView渲染异常解决方法-->
<meta-data
android:name="android.webkit.WebView.EnableSafeBrowsing"
android:value="true" />
正解:manifest的Application中添加属性(看第六条)
android:usesCleartextTraffic="true"
6、Android9.0禁止webview使用http,解决办法在manifest的Application标签下添加属性:
android:usesCleartextTraffic="true"
7、Android7.0调用系统拍照功能异常
异常:
android.os.FileUriExposedException: file:\\storage\emulated\0\KidneyOnlineDoctor\temp\aa.jpg exposed beyond app through ClipData.Item.getUri()
解决方案:FileProvider
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePicPath = tempPathString + UUID.randomUUID().toString() + ".jpg";
File file = FileUtils.createNewFile(takePicPath);
if (file != null) {
Uri photoUri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
photoUri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider", file);
} else {
photoUri = Uri.fromFile(file);
}
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
}
startActivityForResult(intent, REQUEST_CAMERA);