android -- notification使用(转)

转载 2013年12月02日 17:43:04

转载至:http://www.cnblogs.com/playing/archive/2011/03/08/1976722.html

简单记录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);

                     }

              });

       }

}

Android Notification的基本使用和点击跳转中的注意事项

1、Android 中通知栏的基本使用Notification,是一种具有全局效果的通知,可以在系统的通知栏中显示。当 APP 向系统发出通知时,它将先以图标的形式显示在通知栏中。用户可以下拉通知栏查...

Android NotificationManager 和Notification的使用总结(转)

NotificationManager 和Notification的使用总结(转)   文章分类:移动开发   这 ...
  • zqilu
  • zqilu
  • 2014年12月11日 11:16
  • 494

android Notification使用大全

  • 2016年12月08日 14:47
  • 9.02MB
  • 下载

android-Notification点击跳转指定的Activity

今天项目中有这样的一个需求,当程序还没被进程“杀死”的时候,后台推送来了一则消息,这时候不管是程序在前台运行,还是后台中,需要我们以通知栏的方式来通知用户。 对于通知栏,用户操作后有两种情况。 1...

(转)Android之Notification的多种用法

原地址:http://blog.csdn.net/loongggdroid/article/details/17616509/ 我们在用手机的时候,如果来了短信,而我们没有点击查看的话,是不是...
  • duyiqun
  • duyiqun
  • 2016年04月09日 10:25
  • 135

Android NOtification 使用

  • 2011年07月11日 23:02
  • 131KB
  • 下载

android Notification使用例子

  • 2014年04月11日 22:28
  • 2.22MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:android -- notification使用(转)
举报原因:
原因补充:

(最多只允许输入30个字)