1、AndroidManifest.xml注意要同时注册Notification02Activity

<!-- 状态通知栏 Notification -->
        <activity
            android:name="com.example.notification.Notification01Activity"
            android:label="状态通知" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.notification.Notification02Activity"
            android:label="Notification01Activity" >
        </activity>

2、Notification01Activity.java

public class Notification01Activity extends Activity {
    Button button01, button02, button03, button04;
    // 声明通知(消息)管理器
    NotificationManager mNotificationManager;
    Intent mIntent;
    PendingIntent mPendingIntent;
    // 声明Notification对象
    Notification mNotification;

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notification01);
        // 获得四个按钮对象
        button01 = (Button) findViewById(R.id.btn1_notifi);
        button02 = (Button) findViewById(R.id.btn2_notifi);
        button03 = (Button) findViewById(R.id.btn3_notifi);
        button04 = (Button) findViewById(R.id.btn4_notifi);
        // 初始化NotificationManager对象*************
        mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        // 点击通知时转移内容*********查看通知的具体内容
        mIntent = new Intent(Notification01Activity.this,
                Notification02Activity.class);
        // 主要是设置点击通知时显示内容的类***********
        mPendingIntent = PendingIntent.getActivity(Notification01Activity.this,
                0, mIntent, 0);
        // 构造Notification对象
        mNotification = new Notification();
        button01.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View v) {
                /* 状态栏上的通知图标及内容 */
                // 设置通知在状态栏显示的图标
                mNotification.icon = R.drawable.button1;
                // 当我们点击通知时显示的内容
                mNotification.tickerText = "Button01通知内容……";
                // 通知时发出默认声音
                mNotification.defaults = Notification.DEFAULT_SOUND;
                /* ==============展开状态栏的快讯=========== */
                // 设置通知显示的参数
                mNotification.setLatestEventInfo(Notification01Activity.this,
                        "Button01", "Button01通知", mPendingIntent);
                // 可理解为执行这个通知
                mNotificationManager.notify(0, mNotification);
            }
        });
        button02.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                mNotification.icon = R.drawable.button2;
                mNotification.tickerText = "Button02通知内容……";
                mNotification.defaults = Notification.DEFAULT_SOUND;
                mNotification.setLatestEventInfo(Notification01Activity.this,
                        "Button02", "Button02通知", mPendingIntent);
                mNotificationManager.notify(0, mNotification);
            }
        });
        button03.setOnClickListener(new Button.OnClickListener() {

@Override
            public void onClick(View v) {
                mNotification.icon = R.drawable.button3;
                mNotification.defaults = Notification.DEFAULT_SOUND;
                mNotification.tickerText = "Button03通知内容……";
                mNotification.setLatestEventInfo(Notification01Activity.this,
                        "Button03", "Button03通知", mPendingIntent);
                mNotificationManager.notify(0, mNotification);
            }
        });
        button04.setOnClickListener(new Button.OnClickListener() {

@Override
            public void onClick(View v) {
                mNotification.icon = R.drawable.button31;
                mNotification.defaults = Notification.DEFAULT_SOUND;
                mNotification.tickerText = "Button04通知内容……";
                mNotification.setLatestEventInfo(Notification01Activity.this,
                        "Button04", "Button04通知", mPendingIntent);
                mNotificationManager.notify(0, mNotification);
            }
        });
    }

}

3、Notification02Activity.java

public class Notification02Activity extends Activity {

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //这里直接限制一个TextView
        setContentView(R.layout.activity_notification02);
    }
}

4、activity_notification02.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

<TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="状态栏提示演示协助实现界面!" />

</LinearLayout>

5、activity_notification01.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

<Button
        android:id="@+id/btn1_notifi"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button01" />

<Button
        android:id="@+id/btn2_notifi"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button02" />

<Button
        android:id="@+id/btn3_notifi"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button03" />

<Button
        android:id="@+id/btn4_notifi"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button04" />

</LinearLayout>

Android——状态栏通知栏Notification的更多相关文章

  1. Android 状态栏通知Notification、NotificationManager简介

    Notification(通知)一般用在电话,短信,邮件,闹钟铃声,在手机的状态栏上就会出现一个小图标,提示用户处理这个通知,这时手从上方滑动状态栏就可以展开并处理这个通知: 在Android系统中, ...

  2. Android 状态栏通知 Notification

    private NotificationManager manager; private Notification.Builder builder; @Override protected void ...

  3. android显示通知栏Notification以及自定义Notification的View

    遇到的最大的问题是监听不到用户清除通知栏的广播.所以是不能监听到的. 自定义通知栏的View,然后service运行时更改notification的信息. /** * Show a notificat ...

  4. android 创建通知栏Notification

    ///// 第一步:获取NotificationManager NotificationManager nm = (NotificationManager) getSystemService(Cont ...

  5. Android 状态栏通知Notification、NotificationManager详解

    http://www.cnblogs.com/onlyinweb/archive/2012/09/03/2668381.html

  6. Android --通知栏Notification

    参考博客:Android 通知栏Notification的整合 全面学习 (一个DEMO让你完全了解它) //创建一个通知栏的Builder构造类 (Create a Notification Bui ...

  7. Android种使用Notification实现通知管理以及自定义通知栏(Notification示例四)

    示例一:实现通知栏管理 当针对相同类型的事件多次发出通知,作为开发者,应该避免使用全新的通知,这时就应该考虑更新之前通知栏的一些值来达到提醒用户的目的.例如我们手机的短信系统,当不断有新消息传来时,我 ...

  8. Android中使用Notification实现进度通知栏(Notification示例三)

    我们在使用APP的过程中,软件会偶尔提示我们进行版本更新,我们点击确认更新后,会在通知栏显示下载更新进度(已知长度的进度条)以及安装情况(不确定进度条),这就是我们今天要实现的功能.实现效果如下: 在 ...

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

    Notification是在你的应用常规界面之外展示的消息.当app让系统发送一个消息的时候,消息首先以图表的形式显示在通知栏.要查看消息的详情需要进入通知抽屉(notificationdrawer) ...

随机推荐

  1. 【故障处理】ORA-12162: TNS:net service name is incorrectly specified

    本文将给大家阐述一个因未设置系统环境变量ORACLE_SID导致ORA-12162错误的案例.希望大家有所思考. 1.获得有关ORA-12162报错信息的通用表述信息[oracle@asdlabdb0 ...

  2. openstack(liberty): 简单网络连接图

    openstack起初的网络部分是和计算核心nova合在一起的,后来被拆分出来,独立成为一个模块, 现在名为Neutron. 本博文是学习记录,记录的是基于GRE tunnel技术的neutron和计 ...

  3. thymeleaf之fragment

    MUEAS项目,web前端采用thymeleaf作为展示层.这个view解析器,个人觉得非常不错.简单而且性能也比较好!个人觉得比JSP和freemarker之类,简单易用! 今天简单记录一下frag ...

  4. 【性能测试】性能测试总结<三>

    常见性能测试工具: 性能测试工具,从理论上来讲在性能测试过程中使用到的所有工具都可以称其为性能测试工具,通常分为以下几类: 说明: 服务器端性能测试工具:需要支持产生压力和负载,录制和生成脚本,设置和 ...

  5. == Got TLE on OJ? Here is the solution! ==

    As a solo warrior in OJ, I spent about nearly 50% of my time on tackling TLE - that is innumerous ho ...

  6. 剑指offer系列37----数据流中的中位数

    [题目]如何得到一个数据流中的中位数?如果从数据流中读出奇数个数值, * 那么中位数就是所有数值排序之后位于中间的数值. package com.exe8.offer; import java.uti ...

  7. 剑指offer系列26--正则表达式匹配

    [题目]请实现一个函数用来匹配包括’.’和’*‘的正则表达式.模式中的字符’.’表示任意一个字符,而’‘表示它前面的字符可以出现任意次(包含0次). 在本题中,匹配是指字符串的所有字符匹配整个模式.例 ...

  8. windows7使用Source insight上远程修改ubuntu共享内核源码

    由于本人阅读喜欢使用source insight.前段时间接触了linux核代码,而这份代码只能放在ubuntu服务器上编译,刚开始的时候是在windows上修改,完了之后再copy到服务器上去编译, ...

  9. C# Base64字符串转换成图片及图片转换为Base64

    最近有朋友经常会问我一些问题,例如,如何把一个字符串转换成base64字符串,如何把一个二进制文件转换成Base64文件,以及如何转换回原有的文件,在此我把方法写一下   字符串与Base64相互转换 ...

  10. DBA_Oracle性能优化的基本方法概述(方法论)

    2014-12-18 Created By BaoXinjian