Android各版本行为变更

前言

之前突然发现有好多api在各个版本具有不同表达形式,因此在此进行摘录以便日后查询

大纲

1.Android P(9.0)

2.Android O(8.0) 26

3.Android P(7.0) 24

4.Android M(6.0) 23

5.Android L(5.0) 21

正文

1.Android P(9.0)

利用 Wi-Fi RTT 进行室内定位,手机可以确定与接入点的距离
显示屏缺口支持
通知相关,通知渠道
多摄像头支持
引入了 ImageDecoder 类,可提供现代化的图像解码方法。 使用该类取代 BitmapFactory 和 BitmapFactory.Options API
引入了 AnimatedImageDrawable 类,用于绘制和显示 GIF 和 WebP 动画图像
扩展和改进了 Neural Networks API 以加快 Android 设备上机器学习的速度
统一生物识别身份验证对话框

参考:https://developer.android.google.cn/about/versions/pie/android-9.0-changes-all

2.Android O(8.0) 26

1.Notification,新增通知渠道
 

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    //8.0新增通知渠道
    CharSequence name = DeviceInfo.getCurrentChannel();
    int importance = NotificationManager.IMPORTANCE_LOW;   //优先级
    NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
    mChannel.enableLights(false);            //闪灯开关
    mChannel.enableVibration(false);         //振动开关
    mChannel.setShowBadge(false);         //通知圆点开关
    notificationManager.createNotificationChannel(mChannel);
    builder = new Notification.Builder(App.getInstance(), CHANNEL_ID);
} else {
    builder = new Notification.Builder(App.getInstance());
}

2.findViewById 函数现在返回的是 <T extends View>,所以以后 findViewById 就不需要强转了

3.layout边距
`layout_marginVertical`,同时设置 `layout_marginTop` 和 `layout_marginBottom` 属性;
`layout_marginHorizontal`,同时设置 `layout_marginLeft` 和 `layout_marginRight`属性;
`paddingVertical`,同时设置 `paddingTop` 和 `paddingBottom`属性;
`paddingHorizontal`,同时设置 `paddingLeft` 和 `paddingRight`属性;

参考:https://developer.android.google.cn/about/versions/oreo/android-8.0-changes

3.Android P(7.0) 24

1.获取文件uri变更
 

if (Build.VERSION.SDK_INT >= 24) {
    uri = FileProvider.getUriForFile(mActivity,FILE_PROVIDER,file);
} else {
    uri = Uri.fromFile(file);
}

24之前版本直接获取,24以后直接传递file://URI则会报异常:FileUriExposedException
因此需要FileProvider获取

参考:https://developer.android.google.cn/about/versions/nougat/android-7.0-changes

2.PopUpWindow设置锚点view的显示问题

显示都是用showAsDropDown,主要是对PopUpWindow的高度设置不同,7.0以下和7.0显示不同,会全屏显示或是显示不全,因此需要根据版本设置PopUpWindow的高度

if (Build.VERSION.SDK_INT < 24) {
    setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
} else {
    Rect rect = new Rect();
    showDropView.getGlobalVisibleRect(rect);
    //屏幕高度减去 showDropView 的 bottom
    int screenHeight = showDropView.getResources().getDisplayMetrics().heightPixels - rect.bottom;
    setHeight(screenHeight);
}

4.Android M(6.0) 23

运行时权限
使得用户可以在运行 APP 的时候对一些比较敏感的权限进行管理

参考:https://developer.android.google.cn/about/versions/marshmallow/android-6.0-changes

5.Android L(5.0) 21

ART 运行时取代 Dalvik 成为平台默认设置

参考:https://developer.android.google.cn/about/versions/android-5.0-changes

结语

大致总结了一些比较常见的行为变更,更多细节还需参照官方API

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值