android 自定义通知不显示,Android notification设置的图标不显示
跟着谷歌的android fundamental tutorial作安卓通知部分时,在魅族flyme系统上并不显示我设置的通知icon,而是显示默认的应用启动图标。而且奇怪的是我设置的通知是等级最高的,系统给我折叠到了不重要的消息里面也没有声音提示,求教。
target API:26.0
使用的icon是AS自带的透明图标。
我参照的教程地址
public class MainActivity extends AppCompatActivity {
private ToggleButton mToggleButton;
private NotificationManager notificationManager;
private static final int NOTIFICATION_ID=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
notificationManager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mToggleButton= findViewById(R.id.alarmToggle);
//改变togglebutton文字
// mToggleButton.setTextOff("Off");
// mToggleButton.setTextOn("On");
// mToggleButton.setText("Off");
mToggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
String toastMessage;
if (b){
toastMessage=getString(R.string.toggleButton_on);
deliverNotification(MainActivity.this);
}
else {
toastMessage=getString(R.string.toggleButton_off);
notificationManager.cancelAll();
}
Toast.makeText(MainActivity.this,toastMessage,Toast.LENGTH_SHORT).show();
}
});
}
public void deliverNotification(Context context){
Intent notificationIntent = new Intent(context,MainActivity.class);
PendingIntent notificationPendingIntent =PendingIntent.getActivity(
context,NOTIFICATION_ID,notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);
// NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context,"StandUp")
.setSmallIcon(R.drawable.ic_run)
//这里设定的图标是AS里随便找的一个,设置了没效果
.setContentTitle(getString(R.string.notification_title))
.setContentText(getString(R.string.notification_text))
.setContentIntent(notificationPendingIntent)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setDefaults(NotificationCompat.DEFAULT_ALL)
.setAutoCancel(true);
// notificationManager.notify(NOTIFICATION_ID,builder.build());
notificationManager.notify(NOTIFICATION_ID,builder.build());
}
}
android 自定义通知不显示,Android notification设置的图标不显示相关推荐
- 【Qt】使用Qss设置QPushButton图标和显示文本的位置
使用Qss设置QPushButton图标和显示文本的位置 一.背景 在开发中,经常使用到按钮作为一种输入部件,然而很多时候按钮又有不同的开发设计需求,本文重点分享:如何使用Qss来设置按钮的图标和 ...
- android自定义主题背景颜色,Android 自定义SeekBar 实现分段显示不同背景颜色的示例代码...
在最近的开发工作中,要实现一个调色板的进度条,SeekBar要分成10段显示不同颜色,功夫不负有心人,终于实现了这个功能,下面分享给大家 示例图: 1.自定义SeekBar import androi ...
- android 自定义取色器,【Android自定义View】仿Photoshop取色器ColorPicker(二)
ColorPicker 一款仿Photoshop取色器的Android版取色器. 前言 上一篇已经简单介绍了ColorPicker的项目结构以及两种颜色空间,接下来我们详细解析一下ColorPicke ...
- android自定义view生命周期,android基础之自定义view
一.Custom View 1.view的继承关系 view继承关系.png 2.Android 如何绘制试图层次 当activity获取焦点时,它必须提供layout层次的根节点,然后android ...
- android 自定义透明 等待 dialog,Android自定义Dialog内部透明、外部遮罩效果
Android自定义Dialog内部透明.外部遮罩效果 发布时间:2020-09-09 03:01:41 来源:脚本之家 阅读:117 作者:zst1303939801 本文实例为大家分享了Andro ...
- android 自定义view 动画效果,Android自定义view实现阻尼效果的加载动画
效果: 需要知识: 1. 二次贝塞尔曲线 2. 动画知识 3. 基础自定义view知识 先来解释下什么叫阻尼运动 阻尼振动是指,由于振动系统受到摩擦和介质阻力或其他能耗而使振幅随时间逐渐衰减的振动,又 ...
- android 自定义view 硬件加速,Android自定义View(八) -- 硬件加速
Android自定义View(八) – 硬件加速 今天学习自定义View部分的最有一篇:硬件加速因为无法录制GIF,所以本篇内容基本为原博 本文计划根据HenCoder系列文章进行学习,所以代码风格及 ...
- android自定义下拉筛选,android自定义Spinner下拉菜单(下拉列表框)样式
在Android中Spinner就是下拉菜单,它相当于HTML中的标签. Android中提供的Spinner Widget下拉菜单已经非常好用了,样式也适用, 不过我们还是可以通过定义xml的方式来 ...
- android自定义圆角进度条,Android自定义进度条的圆角横向进度条实例详解
1.本文将向你介绍自定义进度条的写法,比较简单,但还是有些知识点是需要注意的: invalidate()方法 RectF方法的应用 onMeasure方法的应用 2.原理 画3层圆角矩形,底层为黑色, ...
最新文章
- Java模板引擎-FreeMarker
- 初一级模拟试题总结(2019.3.2)
- java反射机制+继承设计技巧
- 大数据业务学习笔记_学习业务成为一名出色的数据科学家
- 计算机类对口升学都可以升啥专业,计算机专业对口升学专业试题.doc
- jquery中的ajax 网络请求
- 消息中间件学习总结(2)——RocketMQ之阿里开源消息中间件RocketMQ的前世今生
- java接口自动化书籍_java接口自动化优化(一)
- MariaDB 10.0.X中,动态列支持 JSON 格式来获取数据
- 数据库连接字符串的写法(参考)
- 大数据分析应用在哪些方面
- inventor牙距_滚子链计算基础知识 | Inventor 2018 | Autodesk Knowledge Network
- locust性能测试工具
- love2d 1. 入门
- 【解决】maven install出现fatal error compiling
- Windows10只关闭显卡驱动更新
- 微信刷脸支付php后端,2.1 微信刷脸支付初始化
- SimpleDateFormat api
- unity万能的提示窗口
- MySQL表结构的管理