由于 Google Play 现在限制了上传 APK 的 targetSdkVersion,所以在新项目中就开始把版本号升到最高,这样一来之前前人写的一些代码库就会出现兼容性的问题,比如下载更新 APK 时,FileProvider 问题(我上一篇有讲到过)。比如在下载的过程中,之前写好的通知栏中显示进度。但是在 targetSdkVersion > 26 时,会被屏蔽掉。
- Android 8.0 引入了 Notifycation Channel
- 官方通知文档:https://developer.android.google.cn/training/notify-user/build-notification
在 new NotificationCompat.Builder(context) 之前适配版本是否大于26
mNotifyManager = (NotificationManager) mContext
.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("channel_id", "channel", NotificationManager.IMPORTANCE_LOW);