android 适配android 8.0时遇到的问题
来源:互联网 发布:淘宝客服主要是做什么 编辑:程序博客网 时间:2024/06/03 19:43
前几天某应用平台通知我,说我没有适配android O,让我适配之后再进行上传更新.
虽说android 8.0出了一段时间了,但毕竟常用的机型中没有,所以没有适配.也是个人漏洞
虽说android 8.0出了一段时间了,但毕竟常用的机型中没有,所以没有适配.也是个人漏洞
然后在Pixel XL和Nexus 6P上运行了项目,提示出:
然后看了官方文档:notification channel
以及stackoverflow:stackoverflow
这是我之前的代码:
Notification.Builder builder = new Notification.Builder(getApplicationContext()); builder.setContentTitle("") .setContentText("正在运行中") .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.so_logo)) .setSmallIcon(R.mipmap.so_logo) .setOngoing(true)//设置是否是一个正在执行的通知 .setContentIntent(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT)); // 获取构建好的Notification Notification notification = builder.build(); //设置为前台服务,必须绑定一个notification对象,实际上也就是说如果你想做持久化的Service就得让用户知道,PID是自定义的整数表明notification的ID startForeground(Notification_ID, notification);然后加入了:
NotificationChannel channel = new NotificationChannel(String.valueOf(Notification_ID), MsgService.class.getName(), NotificationManager.IMPORTANCE_LOW); NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); manager.createNotificationChannel(channel);和.setChannelId(String.valueOf(Notification_ID))//该句适配android 8.0 版本
最终就为:NotificationChannel channel = new NotificationChannel(String.valueOf(Notification_ID), MsgService.class.getName(), NotificationManager.IMPORTANCE_LOW); NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); manager.createNotificationChannel(channel); Notification.Builder builder = new Notification.Builder(getApplicationContext()); builder.setContentTitle("") .setContentText("正在运行中") .setChannelId(String.valueOf(Notification_ID))//该句适配android 8.0 版本 .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.so_logo)) .setSmallIcon(R.mipmap.so_logo) .setOngoing(true)//设置是否是一个正在执行的通知 .setContentIntent(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT)); // 获取构建好的Notification Notification notification = builder.build(); //设置为前台服务,必须绑定一个notification对象,实际上也就是说如果你想做持久化的Service就得让用户知道,PID是自定义的整数表明notification的ID startForeground(Notification_ID, notification);
然后再运行项目,便再也不会提示那个不适配的问题了.
阅读全文
0 0
- android 适配android 8.0时遇到的问题
- Android遇到的问题
- android遇到的问题
- android遇到的问题
- 安装Android时遇到的问题
- 配置Android环境时遇到的问题
- 用android dialog 时遇到的问题
- android安装时遇到的问题
- android平时学习时遇到的问题
- android 开发时遇到的环境问题
- Android Studio升级时遇到的问题。
- 导入Android项目时遇到的问题
- android 开发时遇到的问题
- 编写Android时遇到的问题
- Android使用数据库时遇到的问题
- Android Studio打包时遇到的问题
- android调试时遇到的“timeout”问题
- Android开发时遇到的问题
- Java中,abstract使用的场合
- 选择排序——C#实现
- 【oracle】Listener日志监控:tnslsnr日志大小超过4G如何处理;
- 使用JS截取字符串長度
- 锁表解锁sql语句
- android 适配android 8.0时遇到的问题
- leetcode ~~~~~~~~(我也不知道这个题号了。。)
- 自己设计的STM32开发板+NOR+SRAM,STM32F1/F4通用开发板PCB工程文件AD设计,打样验证
- oracle全文索引(全文检索)的介绍,使用和创
- Hash类的merge方法
- Xshell远程Linux上传文件
- EBS報表中的qrcode
- Linux下的strace命令
- List的add方法与addAll方法的区别