android的通知栏的实现
package com.example.mynotification; import android.os.Bundle;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.view.Menu; public class MainActivity extends Activity { public PendingIntent getDefalutIntent(int flags){
PendingIntent pendingIntent= PendingIntent.getActivity(this, 1, new Intent(), flags);
return pendingIntent;
} @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
mBuilder.setContentTitle("測试标题")//设置通知栏标题
.setContentText("測试内容")//设置通知栏显示内容
.setContentIntent(getDefalutIntent(Notification.FLAG_AUTO_CANCEL))//设置通知栏点击意图
//.setNumber(number);
.setTicker("測试通知来啦")//通知栏首次出如今通知栏,带上动画效果
.setWhen(System.currentTimeMillis())//通知栏时间。通常是直接用系统的
.setPriority(Notification.DEFAULT_ALL)//设置通知栏优先级
// .setAutoCancel(true)//用户单击面板后消失
.setOngoing(false)//true,设置他为一个正在进行的通知。他们通常是用来表示一个后台任务,用户积极參与(如播放音乐)或以某种方式正在等待,因此
//占用设备(如一个文件下载,同步操作。主动网络连接)
.setDefaults(Notification.DEFAULT_VIBRATE)//向通知加入声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置。
//使用default属性。能够组合
//Notification.DEFAULT_ALL Notification.DEFAULT_SOUND 加入声音 // requires VIBRATE permission
.setSmallIcon(R.drawable.ic_launcher);
Notification notification = mBuilder.build();
notification.flags = Notification.FLAG_ONGOING_EVENT ;
notification.flags = Notification.FLAG_NO_CLEAR;//点击清除的时候不清除
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
mBuilder.setContentIntent(pendingIntent);
mNotificationManager.notify(0,<span style="font-family: Arial, Helvetica, sans-serif;">notification</span><span style="font-family: Arial, Helvetica, sans-serif;">); </span> } @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }
不知道为什么我的点击还是会清除。郁闷。
android的通知栏的实现的更多相关文章
- android 自定义通知栏
package com.example.mvp; import cn.ljuns.temperature.view.TemperatureView;import presenter.ILoginPre ...
- Android notifications通知栏的使用
app发送通知消息到通知栏中的关键代码和点击事件: package com.example.notifications; import android.os.Bundle; import androi ...
- Android——状态栏通知栏Notification
1.AndroidManifest.xml注意要同时注册Notification02Activity <!-- 状态通知栏 Notification --> <acti ...
- android 沉浸通知栏
IOS的沉浸式通知栏很高大上,通知栏和app统一颜色或样式,很美观.android上面也早就人实现这种效果了. 我在这边也写一个实现通知栏沉浸式的方法,目前只实现了相同颜色. 先要改布局文件xml & ...
- Android:通知栏的使用
非常久没有使用Android的通知功能了,今天把两年前的代码搬出来一看.发现非常多方法都废弃了,代码中各种删除线看的十分不爽.于是乎,打开Google,查看官方文档.学习最新的发送通知栏消息的方法. ...
- Android基础------通知栏
前言:Android通知栏提示笔记 通知几乎是每一款app都拥有的功能 1.发送通知 发送一个通知栏必须用到两个类: NotificationManager . Notification. Noti ...
- android实现通知栏消息
一.原理 消息推送有两种,一种是客户端定时直接到服务器搜索消息,如果发现有新的消息,就获取消息下来:另一种是服务器向客户端发送消息,也就是当有信息消息时,服务器端就会向客户端发送消息. 二.步骤(代码 ...
- Android O 通知栏的"running in the background"
Android O新增的一个特性,系统会在通知栏显示当前在后台运行的应用,其实际是显示启动了前台服务的应用,并且当前应用的Activity不在前台.具体我们看下源码是怎么实现的. 1 APP调用sta ...
- Android Notification通知栏使用
package com.example.mynotifycation; import android.app.Activity; import android.app.Notification; im ...
随机推荐
- Tiny microcontroller hosts dual dc/dc-boost converters
Batteries are the typical power sources for portable-system applications, and it is not unusual thes ...
- 对 dpif_class 结构体的一点认识
类 dpif_class 抽象的是OVS交换机用户空间和内核层datapath的通信接口(通过netlink),分层是出于性能和生产效率的考虑,通过接口dpif_class,用户层ovs-v ...
- Windows平台下如何使用Android NDK
鉴于有些同学想要学习NDK,但在网上很难找到一个讲解比较清楚.按照步骤操作可以比较顺利学会NDK的文章,所以写了此篇教程. 一.学习本篇教程需要具备的条件: 1. 了解JAVA中JNI的概念.好处以及 ...
- 为什么要用<!DOCTYPE>声明
实例: 我们常常会看到类似这种代码: <!DOCTYPE html> <html> <head> <title>文档的标题</title> ...
- poi 技术动态更新 Excel模板内容,动态更新内容
1.控制器方法 private URL base = this.getClass().getResource(""); /** * 流拍之后,可以下载询价单 * * @param ...
- 14.ThreadLocal
ThreadLocal 1.线程局部变量,是一种多线程并发访问变量的解决方案,与同步技术 synchronize 加锁的方式不同,threadlocal完全不提供锁,而使用 空间 ...
- 【USACO1.2_2】★Transformations 方块转换
一块N x N(1<=N<=10)正方形的黑白瓦片的图案要被转换成新的正方形图案.写一个程序来找出将原始图案依照下面列转换方法转换成新图案的最小方式: 1:转90度:图案按顺时针转90度. ...
- wsgi & cgi的一些概念解释
可以看这里 https://www.zhihu.com/question/19998865 如何理解 CGI, WSGI?修改 写补充说明 举报 添加评论 分享 • 邀请回答 默认排序 按时间排序 1 ...
- Django admin管理
admin的配置 admin是django强大功能之一,它能共从数据库中读取数据,呈现在页面中,进行管理.默认情况下,它的功能已经非常强大,如果你不需要复杂的功能,它已经够用,但是有时候,一些特殊的功 ...
- VMware ESXi 5.5无法与Windows 2012 NTP Server同步时间
这次笔者需要面对的环境对时间的同步有比较高的要求, 而虚拟化的环境中时间是比较容易出问题的, 您可以参考上一篇博文为什么Domain controller上的time synchronization非 ...