notification使用

package com.yarin.android.Examples_04_23;

import android.app.Activity;

import android.app.Notification;

import android.app.NotificationManager;

import android.app.PendingIntent;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

public class Activity01 extends Activity

{

       Button    m_Button1, m_Button2, m_Button3, m_Button4;

       //声明通知(消息)管理器

       NotificationManager      m_NotificationManager;

       Intent                           m_Intent;

       PendingIntent        m_PendingIntent;

       //声明Notification对象

       Notification           m_Notification;

       /** Called when the activity is first created. */

       @Override

       public void onCreate(Bundle savedInstanceState)

       {

              super.onCreate(savedInstanceState);

              setContentView(R.layout.main);

              //初始化NotificationManager对象

              m_NotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

              //获取4个按钮对象

              m_Button1 = (Button) findViewById(R.id.Button01);

              m_Button2 = (Button) findViewById(R.id.Button02);

              m_Button3 = (Button) findViewById(R.id.Button03);

              m_Button4 = (Button) findViewById(R.id.Button04);

              //点击通知时转移内容

              m_Intent = new Intent(Activity01.this, Activity02.class);

              //主要是设置点击通知时显示内容的类

              m_PendingIntent = PendingIntent.getActivity(Activity01.this, 0, m_Intent, 0);

              //构造Notification对象

              m_Notification = new Notification();

              m_Button1.setOnClickListener(new Button.OnClickListener() {

                     public void onClick(View v)

                     {

                            //设置通知在状态栏显示的图标

                            m_Notification.icon = R.drawable.img1;

                            //当我们点击通知时显示的内容

                            m_Notification.tickerText = "Button1通知内容...........";

                            //通知时发出默认的声音

                            m_Notification.defaults = Notification.DEFAULT_SOUND;

                            //设置通知显示的参数

                            m_Notification.setLatestEventInfo(Activity01.this, "Button1", "Button1通知", m_PendingIntent);

                            //可以理解为执行这个通知

                            m_NotificationManager.notify(0, m_Notification);

                     }

              });

              m_Button2.setOnClickListener(new Button.OnClickListener() {

                     public void onClick(View v)

                     {

                            m_Notification.icon = R.drawable.img2;

                            m_Notification.tickerText = "Button2通知内容...........";

                            //通知时震动

                            m_Notification.defaults = Notification.DEFAULT_VIBRATE;

                            m_Notification.setLatestEventInfo(Activity01.this, "Button2", "Button2通知", m_PendingIntent);

                            m_NotificationManager.notify(0, m_Notification);

                     }

              });

              m_Button3.setOnClickListener(new Button.OnClickListener() {

                     public void onClick(View v)

                     {

                            m_Notification.icon = R.drawable.img3;

                            m_Notification.tickerText = "Button3通知内容...........";

                            //通知时屏幕发亮

                            m_Notification.defaults = Notification.DEFAULT_LIGHTS;

                            m_Notification.setLatestEventInfo(Activity01.this, "Button3", "Button3通知", m_PendingIntent);

                            m_NotificationManager.notify(0, m_Notification);

                     }

              });

              m_Button4.setOnClickListener(new Button.OnClickListener() {

                     public void onClick(View v)

                     {

                            m_Notification.icon = R.drawable.img4;

                            m_Notification.tickerText = "Button4通知内容..........";

                            //通知时既震动又屏幕发亮还有默认的声音

                            m_Notification.defaults = Notification.DEFAULT_ALL;

                            m_Notification.setLatestEventInfo(Activity01.this, "Button4", "Button4通知", m_PendingIntent);

                            m_NotificationManager.notify(0, m_Notification);

                     }

              });

       }

}

  

时间: 2024-12-12 11:44:55

notification使用的相关文章

通知栏Notification在不同手机上显示的问题总结

可以参照http://blog.csdn.net/vipzjyno1/article/details/25248021,这里面关于通知的写的不错,也很全面,我的这篇主要是记录自己在适配上遇到的问题. 通知的统一的创建方式: NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext); 而通知的管理则是使用NotificationManager是用来管理通知的,使用如下:先初始化用到的系统服务,然后调

Apple Notification Center Service--ANCS【转】

Apple Notification Center Service 转自:http://studentdeng.github.io/blog/2014/03/22/ancs/ MAR 22ND, 2014 | COMMENTS 名词解释与约定 名词解释 Apple Notification Center Service 简称 ANCS. ANCS 服务(iOS设备,如iPhone,iPad等)的publisher 称为 Notification Provider. 任意的ANCS服务的clien

Notification Centers 通知中心

Notification Centers 通知中心 A notification center manages the sending and receiving of notifications. It notifies all observers of notifications meeting specific criteria. The notification information is encapsulated in NSNotification objects. Client o

Mobile Push Notification

In one embodiment, a method includes sending to a mobile client computing device a first notification through a real-time push service, the first notification including content and being associated with a stateful object; the method also includes, in

Java 线程第三版 第四章 Thread Notification 读书笔记

一.等待与通知 public final void wait() throws InterruptedException 等待条件的发生. public final void wait(long timeout) throws InterruptedException 等待条件的发生.如果通知没有在timeout指定的时间内发生,它还是会返回. public final void wait(long timeout, int nanos) throws InterruptedException

Android-自定义Notification

Android-自定义Notification 2014年4月26日 消息栏的消息,想必各位Android发烧友很清楚知道是什么,比如我们下载了一个应用,它可能会定时推送些消息到我们的手机中,比如微信消息送达的时候,可能会在通知栏显示.本博文介绍如何自定义一个Notification,很简单的东西,这里小巫只是把它整理出来,奉上demo. 先来看看效果图: 附上源码:http://download.csdn.net/detail/wwj_748/7259815 有兴趣的朋友可以加本人创建的群,里

通知(Notification)

1.通知的基本用法 //创建 NotificationManager 实例 NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notification = new NotificationCompat.Builder(this) .setContentTitle("This is title") //标题 .setContent

Notification的基本用法以及使用RemoteView实现自定义布局

Notification的作用 Notification是一种全局效果的通知,在系统的通知栏中显示.既然作为通知,其基本作用有: 显示接收到短消息.即时信息等 显示客户端的推送(广告.优惠.新闻等) 显示正在进行的事物(后台运行的程序,如音乐播放进度.下载进度) Notification的基本操作: Notification的基本操作主要有创建.更新和取消三种.一个Notification的必要属性有三项,如果不设置的话在运行时会抛出异常: 小图标,通过setSmallIcon方法设置 标题,通

Android中使用Notification实现宽通知栏(Notification示例二)

Notification是在你的应用常规界面之外展示的消息.当app让系统发送一个消息的时候,消息首先以图表的形式显示在通知栏.要查看消息的详情需要进入通知抽屉(notificationdrawer)中查看.通知栏和通知抽屉 (notificationdrawer)都是系统层面控制的,你可以随时查看,不限制于app. Notification 的设计: 作为android UI中很重要的组成部分,notification拥有专属于自己的设计准则. Notification的界面元素在通知抽屉中的

安卓学习之通知(Notification)

安卓中创建通知需要借助NotificationManager来对通知进行管理.可以调用Context的getsSystemService()方法来获得. getsSystemService()方法接收一个参数,这个参数是字符串,用于指定哪一个服务.Context.NOTIFICATION_SERVICE 就是指定通知服务. 这个方法返回一个Object对象,所欲需要进行强制转换. NotificationManager manager = (NotificationManager) getSys