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. 【转】用 SVN Importer 实现 CSVNT 到 SVN 的转换

    转载地址:http://www.blogjava.net/yongbing/archive/2007/03/04/101761.html 用 SVN Importer 实现 CSVNT 到 SVN 的 ...

  2. windows上安装apache python mod_python

    综述:   windows上安装apache python mod_python的例子.教程甚至图解都不少:但作为新手还是会出错,而且一时无法快速排解. 在此笔者将根据自己的实践经验,给出几个需要注意 ...

  3. (翻译)理解Java当中的回调机制

    原文地址:http://cleancodedevelopment-qualityseal.blogspot.com/2012/10/understanding-callbacks-with-java. ...

  4. Oracle同义词创建及其作用

    Oracle的同义词(synonyms)从字面上理解就是别名的意思,和试图的功能类似,就是一种映射关系.本文介绍如何创建同义词语句,删除同义词以及查看同义词语句. oracle的同义词总结: 从字面上 ...

  5. 一些常用的SQL查询语句

    学习网站:http://www.w3cschool.cc/sql/sql-tutorial.html 一:查询所有表的属性 SELECT 'ALTER TABLE '+ CASE WHEN O.sch ...

  6. HTML DOM事件

    HTML DOM事件 1.HTML事件包括: (1)当用户点击鼠标时: (2)当页面已加载时: (3)当图像已加载时: (4)当鼠标移动到元素上时: (5)当输入字段被改变时: (6)当提交HTML表 ...

  7. 11个让你吃惊的 Linux 终端命令

    原文:http://linux.about.com/od/commands/tp/11-Linux-Terminal-Commands-That-Will-Rock-Your-World.htm 作者 ...

  8. .Net文件*夹*操作

    一.文件夹操作 Directory类,DirectoryInfo类.使用using System.IO命名空间 (一)创建文件夹 方法一: private string path = @"F ...

  9. BZOJ 3434 时空穿梭

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3434 题意: 思路: const int mod=10007; const int N=1 ...

  10. [3D] 基本概念

    [3D] 基本概念 环境光:对场景中所有的对象都提供了固定不变的照明.点光源:是从一个点发出的光.灯泡就可以理解为点光源.聚光源:正如它的的名字一样,是有方向和强弱的,电筒就是典型的聚光源. 方向光: ...