一、android 8.0以发送通知必须注册渠道
要能够在 Android 8.0 及更高版本上提供通知,首先必须向 createNotificationChannel() 传递 NotificationChannel 的实例,以便在系统中注册应用的通知渠道。
private fun createNotificationChannel() {// Create the NotificationChannel, but only on API 26+ because// the NotificationChannel class is new and not in the support libraryif (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {val name = getString(R.string.channel_name)val descriptionText = getString(R.string.channel_description)val importance = NotificationManager.IMPORTANCE_DEFAULT
val channel = NotificationChannel(CHANNEL_ID, name, importance).apply {
description
=descriptionText
}// Register the channel with the systemval notificationManager: NotificationManager =
getSystemService
(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager
.createNotificationChannel(channel)}}
具体参考:https://developer.android.google.cn/training/notify-user/build-notification.html#kotlin
二、Android 8.0 安装权限问题
在 Android 8.0 中,安装未知应用权限提高了安装未知来源应用时的安全性。此权限与其他运行时权限一样,会与应用绑定,在安装时进行提示,确保用户授予使用安装来源的权限后,此权限才会提示用户安装应用。在运行 Android 8.0 或更高版本的设备上使用此权限时,恶意下载程序将无法骗取用户安装未获得预先授权的应用,所以我们需要加入安装apk文件的权限
<uses-permissionandroid:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
打开apk文件也变化了
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
cameraFileUri = FileProvider.getUriForFile(mContext, "com.xx.xxx.fileProvider[authorities 对应的值]", new File(saveCamerePath, saveCameraFileName));
} else {
cameraFileUri = Uri.fromFile(new File(saveCamerePath, saveCameraFileName));
}
在AndroidManifest.xml中添加如下代码
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="app的包名.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
可参考:https://blog.csdn.net/sinat_36533134/article/details/88558291
三、Android 9.0 https适配问题
参考:https://blog.csdn.net/oZhuiMeng123/article/details/91534478
四、动态权限申请
参考:http://www.imooc.com/article/255297
其它参考:https://blog.csdn.net/ShareUs/article/details/89278489