安卓SDK升级遇到的问题

安卓系统版本与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);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值