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. float浮动与清除浮动

    浮动: 浮动的框可以左右移动,直到它的边缘碰到包含框或另一个浮动框的边框为止.文档的普通流中的块框会当浮动框不存在一样.但会影响内联框(通常是文本)的排列. 属性值有:left,right,none; ...

  2. ACM题目————The partial sum problem

    描述 One day,Tom’s girlfriend give him an array A which contains N integers and asked him:Can you choo ...

  3. ACM题目————STL练习之 懒省事的小明(优先队列)

    描述 小明很想吃果子,正好果园果子熟了.在果园里,小明已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆.小明决定把所有的果子合成一堆. 因为小明比较懒,为了省力气,小明开始想点子了: 每一 ...

  4. 八大排序算法之三选择排序—简单选择排序(Simple Selection Sort)

    基本思想: 在要排序的一组数中,选出最小(或者最大)的一个数与第1个位置的数交换:然后在剩下的数当中再找最小(或者最大)的与第2个位置的数交换,依次类推,直到第n-1个元素(倒数第二个数)和第n个元素 ...

  5. ScheduledExecutorService定时周期执行指定的任务

    示例代码 package com.effective.common.concurrent.execute; import java.text.DateFormat; import java.text. ...

  6. sql 2000以及2005以上获取数据库中所有的表(不包括系统表)

    ---------------------------------------------------------------------------- --sql 2005以上数据库 --- 获取数 ...

  7. Linux下启动Oracle

    切换到oracle用户 su - oracle   启动监听 lsnrctl start   确认是不是想要启动的oracle实例 echo $ORACLE_SID   如果不是,切换SID  ora ...

  8. c#之双色球

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  9. 多校赛3- Painter 分类: 比赛 2015-07-29 19:58 3人阅读 评论(0) 收藏

    D - Painter Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status P ...

  10. Poj(3686),最小权匹配,多重匹配,KM

    题目链接 The Windy's | Time Limit: 5000MS | Memory Limit: 65536K | | Total Submissions: 4939 | Accepted: ...