Android notifications通知栏的使用
app发送通知消息到通知栏中的关键代码和点击事件:
package com.example.notifications; import android.os.Bundle;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.view.Menu;
import android.view.View; public class MainActivity extends Activity { public static final int notifi_id=0x1;
public static final int notifi_id2=0x2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); } public void sendNotifi(View v){
NotificationCompat.Builder builder=new NotificationCompat.Builder(this);
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setContentTitle("您有一条新消息");
builder.setContentText("新年快乐!");
builder.setTicker("新消息");
builder.setDefaults(Notification.DEFAULT_ALL);
//builder.setAutoCancel(true);
Intent intent=new Intent(this,Second.class);
PendingIntent pi=PendingIntent.getActivity(this, , intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pi);
//builder.setOngoing(true);//常驻通知
//创建一个对象通知
Notification n=builder.build();
//获取系统的通知管理器,然后发送通知
NotificationManager nm=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(notifi_id,n);
} public void sendNotifi2(View v){
NotificationCompat.Builder builder=new NotificationCompat.Builder(this);
builder.setSmallIcon(R.drawable.ic_launcher);
/*builder.setContentTitle("您有一条新消息");
builder.setContentText("新年快乐!");*/ //设置大图样式
NotificationCompat.InboxStyle style=new NotificationCompat.InboxStyle();
style.setBigContentTitle("大通知");
style.addLine("冬天");
style.addLine("下雪了");
builder.setStyle(style);
Notification n=builder.build();
NotificationManager nm=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(notifi_id2,n);
} }
Android notifications通知栏的使用的更多相关文章
- [转]ANDROID NOTIFICATIONS USING CORDOVA AND IONIC
本文转自:http://intown.biz/2014/04/11/android-notifications/ ANDROID NOTIFICATIONS USING CORDOVA AND ION ...
- Android:通知栏的使用
非常久没有使用Android的通知功能了,今天把两年前的代码搬出来一看.发现非常多方法都废弃了,代码中各种删除线看的十分不爽.于是乎,打开Google,查看官方文档.学习最新的发送通知栏消息的方法. ...
- android 自定义通知栏
package com.example.mvp; import cn.ljuns.temperature.view.TemperatureView;import presenter.ILoginPre ...
- Android——状态栏通知栏Notification
1.AndroidManifest.xml注意要同时注册Notification02Activity <!-- 状态通知栏 Notification --> <acti ...
- android 沉浸通知栏
IOS的沉浸式通知栏很高大上,通知栏和app统一颜色或样式,很美观.android上面也早就人实现这种效果了. 我在这边也写一个实现通知栏沉浸式的方法,目前只实现了相同颜色. 先要改布局文件xml & ...
- android的通知栏的实现
package com.example.mynotification; import android.os.Bundle; import android.app.Activity; import an ...
- Android基础------通知栏
前言:Android通知栏提示笔记 通知几乎是每一款app都拥有的功能 1.发送通知 发送一个通知栏必须用到两个类: NotificationManager . Notification. Noti ...
- android实现通知栏消息
一.原理 消息推送有两种,一种是客户端定时直接到服务器搜索消息,如果发现有新的消息,就获取消息下来:另一种是服务器向客户端发送消息,也就是当有信息消息时,服务器端就会向客户端发送消息. 二.步骤(代码 ...
- 自定义android 音乐通知栏 ——可伸缩扩展
Android custom notification for music player Example In this tutorial, you will learn how to creat ...
随机推荐
- git 冲突
git中冲突会用特殊的标记 (<<<<<<<=======>>>>>>>) 特殊标记<<<< ...
- c#调用c++的dll,错误篇
"LIPS.vshost.exe"(托管(v4.0.30319)): 已加载"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Sys ...
- RTC系统
http://blog.csdn.net/fanqipin/article/details/8089995 一. RTC及驱动简介 RTC即real time clock实时时钟,主要用于为操作系统提 ...
- Scrapy学习教程
http://scrapy-chs.readthedocs.io/zh_CN/0.24/intro/tutorial.html 在线学习教程: http://learnpythonthehardway ...
- linux lamp服务器安装配置
1 安装Apache服务器 yum -y install httpd httpd-devel 如何查看服务: systemctl | grep httpd 启动apache: service htt ...
- C语言100个经典算法
POJ上做做ACM的题 语言的学习基础,100个经典的算法C语言的学习要从基础开始,这里是100个经典的算法-1C语言的学习要从基础开始,这里是100个经典的算法 题目:古典问题:有一对兔子,从出生后 ...
- 2016年11月13日 星期日 --出埃及记 Exodus 20:4
2016年11月13日 星期日 --出埃及记 Exodus 20:4 "You shall not make for yourself an idol in the form of anyt ...
- android 入门 001 (界面布局)
学android 首先学会怎么布局界面,我开始是学.net的,因工作需要学习一下安卓,外行写的不好,请多多见谅指教 .这一篇文章然我们来学习一下四种布局吧! RelativeLayout(相对布局) ...
- 一次编译Android源码实验
注意,本文只供参考,是老文章 1.必要的软件环境 sudo apt-get install build-essential sudo apt-get install make sudo apt-get ...
- QT笔记之实现阴影窗口
方法一: 代码实现 在窗口构造函数中加入:setAttribute(Qt::WA_TranslucentBackground),保证不被绘制上的部分透明 重写void paintEvent(QPain ...