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通知栏的使用的更多相关文章

  1. [转]ANDROID NOTIFICATIONS USING CORDOVA AND IONIC

    本文转自:http://intown.biz/2014/04/11/android-notifications/ ANDROID NOTIFICATIONS USING CORDOVA AND ION ...

  2. Android:通知栏的使用

    非常久没有使用Android的通知功能了,今天把两年前的代码搬出来一看.发现非常多方法都废弃了,代码中各种删除线看的十分不爽.于是乎,打开Google,查看官方文档.学习最新的发送通知栏消息的方法. ...

  3. android 自定义通知栏

    package com.example.mvp; import cn.ljuns.temperature.view.TemperatureView;import presenter.ILoginPre ...

  4. Android——状态栏通知栏Notification

    1.AndroidManifest.xml注意要同时注册Notification02Activity <!-- 状态通知栏 Notification -->        <acti ...

  5. android 沉浸通知栏

    IOS的沉浸式通知栏很高大上,通知栏和app统一颜色或样式,很美观.android上面也早就人实现这种效果了. 我在这边也写一个实现通知栏沉浸式的方法,目前只实现了相同颜色. 先要改布局文件xml & ...

  6. android的通知栏的实现

    package com.example.mynotification; import android.os.Bundle; import android.app.Activity; import an ...

  7. Android基础------通知栏

    前言:Android通知栏提示笔记 通知几乎是每一款app都拥有的功能 1.发送通知 发送一个通知栏必须用到两个类:  NotificationManager . Notification. Noti ...

  8. android实现通知栏消息

    一.原理 消息推送有两种,一种是客户端定时直接到服务器搜索消息,如果发现有新的消息,就获取消息下来:另一种是服务器向客户端发送消息,也就是当有信息消息时,服务器端就会向客户端发送消息. 二.步骤(代码 ...

  9. 自定义android 音乐通知栏 ——可伸缩扩展

    Android custom notification for music player Example   In this tutorial, you will learn how to creat ...

随机推荐

  1. Java 如何快速序列化

    1,定义变量

  2. word中设置前几页为罗马数字,后几页设置为阿拉伯数字

    假如第1-5页摘要部分页脚要是罗马数字,第6页开始是正文部分是阿拉伯数字,起始页为1. WORD2003 1.将光标定位在第5页末尾处,在菜单栏中依次点击“插入——分隔符——(分节符类型)下一页”.按 ...

  3. Python相对路径转绝对路径,绝对路径转相对路径

    1.绝对路径转相对路径 print os.path.relpath("d:/MyProj/MyFile.txt") #..\MyProj\MyFile.txt 是根据当前路径的相对 ...

  4. 干净的卸载Oracle

    一.在oracle11G以前卸载oracle会存在卸载不干净,导致再次安装失败的情况,在运行services.msc打开服务,停止Oracle的所有服务. 二. oracle11G自带一个卸载批处理\ ...

  5. Codeforces Round #368 (Div. 2) B

    Description Masha wants to open her own bakery and bake muffins in one of the n cities numbered from ...

  6. 2016年6月26日 星期日 --出埃及记 Exodus 14:23

    2016年6月26日 星期日 --出埃及记 Exodus 14:23 The Egyptians pursued them, and all Pharaoh's horses and chariots ...

  7. enc

    enc [问题背景] zhx 和他的妹子聊天. [问题描述] 考虑一种简单的加密算法. 假定所有句子都由小写英文字母构成,对于每一个字母,我们将它唯一地映射到另一个字母.例如考虑映射规则: a-> ...

  8. C# 发送邮件代码

    C# 发送邮件代码 MailMessage mailMsg = new MailMessage(); //using System.Net; 引用 mailMsg.From = new MailAdd ...

  9. 【Java】聊聊常用的摘要算法,比如MD5

    摘要算法的特性 摘要算法的目的的将信息进行简单地摘要,将任意长的信息摘要成固定长的信息.比如MD5,将任意长的信息摘要成128位的摘要. 不可逆的,将报文摘要成一段信息后,无法通过摘要信息还原会报文. ...

  10. VC++ 利用MAPI实现在程序中调用默认的电子邮件程序发送EMAIL(可以添加附件)。

    1.利用ShellExecute 可以条用默认邮件客户端,但不能发送带附件的邮件 mailto:用户账号@邮件服务器地址?subject=邮件主题&body=邮件正文   如:ShellExe ...