1、安装应用需要AndroidManifest中添加如下权限
<uses-permissionandroid:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
2、通知消息需要提供通知渠道才能显示
//通知渠道id
val channelId = "channelId"
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//通知渠道名称
val channelName = "channelName"
//通知渠道重要程度
val importance = NotificationManager.IMPORTANCE_HIGH
//构建通知渠道
val channel = NotificationChannel(channelId, channelName, importance)
//设置通知渠道描述
channel.description = ""
//向系统注册通知渠道,注册后则不能修改重要性以及其他通知行为,但可以删除
notificationManager.createNotificationChannel(channel)
}
val notification = NotificationCompat.Builder(this, "channelId")
.setContentTitle("标题")
.setContentText("消息内容")
.setSmallIcon(R.drawable.ic_launcher_background)
.setAutoCancel(true)//点击自动消失
.build()
//通知id,每个通知都应该不同否则会覆盖
val notifyId = 1
notificationManager.notify(notifyId, notification)
注:(1)渠道分组
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
//渠道组id
val channelGroupId = "chanelGroupId"
//渠道名称
val channelGroupName = "chanelGroupName"
val channelGroup = NotificationChannelGroup(channelGroupId, channelGroupName)
notificationManager.createNotificationChannelGroup(channelGroup)
//渠道
val channel = NotificationChannel("channelId", "channelName", NotificationManager.IMPORTANCE_HIGH)
//渠道设置分组
channel.group = channelGroupId
notificationManager.createNotificationChannel(channel)
(2)其他api
//查询渠道组列表
notificationManager.notificationChannelGroups
//查询渠道列表
notificationManager.notificationChannels
//删除渠道组
notificationManager.deleteNotificationChannelGroup("groupId")
//删除渠道
notificationManager.deleteNotificationChannel("channelId")
3、前台服务(详见)
4、自动调整字体大小(详见)
5、自适应图标(详见)
对于国内手机一般都标准化了桌面图标,即APP提供的是正方形的icon,国内手机厂商也会处理成系统统一的风格,而8.0之前Google桌面图标未做处理,圆角图标、方角图标、圆形图标共存现象,8.0开始通过适配,来满足和系统一致的风格。
6、新增属性(对于支持8.0以下设备的项目,不要使用这些属性,可能部分机型上无效)
android:layout_marginHorizontal 等同marginStart和marginEnd设置相同值
android:layout_marginVertical 等同marginTop和marginBottom设置相同值
android:layout_paddingHorizontal 等同paddingStart和paddingEnd设置相同值
android:layout_paddingVertical 等同paddingTop和paddingBottom设置相同值
7、新增权限
(1)ANSWWER_PHONE_CALLS:接听呼入电话权限(需要动态申请),acceptRingingCall()进行接听操作
(2)READ_PHONE_NUMBERS:读取设备存储的电话号码(需要动态申请)