`
xuyuanshuaaa
  • 浏览: 389425 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

状态栏提示Notification

阅读更多
当有未接电话或者短信时,在手机顶部状态栏就会出现一个小图标,提示用户没有处理的快讯,android提供了NotificationManager来管理状态栏信息,提供Notification处理这些快讯信息
示例
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical" android:layout_width="fill_parent"
	android:layout_height="fill_parent">
	<TextView android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:text="@string/hello" />
	<Button android:text="Button01" android:id="@+id/Button01"
		android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>	
</LinearLayout>


main2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical" android:layout_width="fill_parent"
	android:layout_height="fill_parent">
	<TextView android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:text="多谢使用" />
</LinearLayout>


Activity.java
public class Test_Notification extends Activity {  
    /** Called when the activity is first created. */  
    private Button btn1;  
    private Notification notification;  
    private NotificationManager notificationManager;  
    private Intent intent;  
    private PendingIntent pendIntent;  
  
    @Override  
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.main);  
        btn1 = (Button) this.findViewById(R.id.Button01);  
        notificationManager = (NotificationManager) this  
                .getSystemService(NOTIFICATION_SERVICE);// 获取系统服务(消息管理)  
        // 点击通知时转移内容  
        intent = new Intent(this, Activity2.class);  
        // 设置点击通知时显示内容的类  
       // 和Intent不同,构造pendIntent是Nofication.setLastestEventInfo参数需要
        pendIntent = PendingIntent.getActivity(this, 0, intent, 0);  
        notification = new Notification();  
        btn1.setOnClickListener(new OnClickListener() {  
  
            @Override  
            public void onClick(View v) {  
                // TODO Auto-generated method stub  
                notification.icon = R.drawable.img1;// 设置在状态栏显示的图标  
                notification.tickerText = "Button1通知内容.......";//设置在状态栏显示的内容  
                notification.defaults = Notification.DEFAULT_SOUND;// 默认的声音  
                // 设置通知显示的参数  
                notification.setLatestEventInfo(Test_Notification.this,  
                        "Button1", "Button1通知", pendIntent);  
                notificationManager.notify(0, notification);// 执行通知.  
            }  
  
        });  
    }  
}  
分享到:
评论

相关推荐

    Android 在状态栏添加Notification信息图标及提示.rar

    这个例子演示Android 在状态栏添加Notification信息图标及提示,相信大家对这个功能已经不陌生了,手机中安装的APP,一般都会在后台运行,时不时会在手机顶部的状态栏中显示应用的图标,滑出状态栏会看到详细的信息...

    Android中使用Notification实现状态栏的通知

    在使用手机时,当有未接来电或者新短消息时,手机会给出响应的提示信息,这些提示信息通常会显示到手机屏幕的状态栏上。 Android也提供了用于处理这些信息的类,它们是Notification和NotificationManager。其中,...

    Android使用Notification在状态栏上显示通知

    在使用手机时,当有未接来电或者是新短消息时,手机会给出相应的提示信息,这些提示信息通常会显示到手机屏幕的状态栏上。Android也提供了用于处理此类信息的类,他们是Notification和NotificationManager。其中,...

    BroadcastBroadcast

    3、 当点击 发送广播 发送广播 时在状态栏提示 中有显时在状态栏提示 中有显时在状态栏提示 中有显时在状态栏提示 中有显时在状态栏提示 中有显4、 点击下拉状态提示栏,相应 点击下拉状态提示栏,相应 点击下拉状态...

    (0092)-iOS/iPhone/iPAD/iPod源代码-状态栏(Status Bar)-Discreet Notification View

    "在窗口顶端或者下端弹出自定义的提示视图(notification View)。例如,图中上方的黑色标签“This is the notification.""。可用于显示当前app的状态,用户操作的提示等等。" 注意:请在Mac下解压使用

    Android Notification

    Notification 模拟收到短信,数据下载的状态栏提示 博客地址:http://blog.csdn.net/csdnyuandaimaxuexi/article/details/49425087

    react-native-android-notification-listener:React Native Android Notification Listener-监听所有应用程序的状态栏通知

    React Native Android Notification Listener是一个库,可让您侦听来自所有应用程序的状态栏通知。 (仅限Android) 安装 $ yarn add react-native-android-notification-listener 或者 $ npm install react-...

    仿系统消息推送状态栏提示框

    JKNotifier通知栏提示框,仿系统消息推送状态栏提示框,源码JKNotifier,JKNotifier JKNotifier,when a notification pushed and app is UIApplicationStateActive,JKNotifier wiil show in statusbar like ...

    Android中Notification 提示对话框

    一、Notification用于状态栏显示通知的控件,在不同的设备上面Notification是不一样的 二、Notification的基本布局 元素组成: Icon/Photo:大图标 Tiltle/Name:标题 Message:内容消息 Timestamp:通知的时间,...

    Android开发之Notification通知用法详解

    根据activity的生命周期,在activity不显示时,会执行onStop函数(比如按下home键),所以你在onStop函数(按退出键除外)里面把notification放在通知栏里,再此显示时,把notification从通知栏里去掉。或者,只要程序...

    Android编程开发之NotiFication用法详解

    notification就是通知的意思,安卓中指通知栏,一般用在电话,短信,邮件,闹钟铃声,在手机的状态栏上就会出现一个小图标,提示用户处理这个快讯,这时手从上方滑动状态栏就可以展开并处理这个快讯。 在帮助文档中...

    android通知入门小例子

    通知(Notification)是 ...条通知后,手机最上方的状态栏中会显示一个通知的图标,下拉状态栏后可以看到通知的详 细内容。 使用:当程序进入到后台的时候我们才需要使用通知,所以在广播接收器和服务中使用通知较多。

    Android中Notification的用法汇总

    我们在用手机的时候,如果来了短信,而我们没有点击查看的话,是不是在手机的最上边的状态栏里有一个短信的小图标提示啊?你是不是也想实现这种功能呢?今天的Notification就是解决这个问题的。 我们也知道Android...

    Android Notification的多种用法总结

    我们在用手机的时候,如果来了短信,而我们没有点击查看的话,是不是在手机的最上边的状态栏里有一个短信的小图标提示啊?你是不是也想实现这种功能呢?今天的Notification就是解决这个问题的。  我们也知道...

    Android中Notification用法实例总结

    我们在用手机的时候,如果来了短信,而我们没有点击查看的话,是不是在手机的最上边的状态栏里有一个短信的小图标提示啊?你是不是也想实现这种功能呢?今天的Notification就是解决这个问题的。 我们也知道Android...

    Android开发之使用通知栏显示提醒信息的方法

    本文实例讲述了Android开发之使用通知栏显示提醒信息的方法。分享给大家供大家参考,具体... //初始化通知对象 p1:通知的图标 p2:通知的状态栏显示的提示 p3:通知显示的时间 Notification notification = new Notifica

    Discreet Notification View(iPhone源代码)

     在窗口状态栏(UIStatusBar)顶端或者下端弹出自定义的提示视图(notification View)。例如,图中上方的黑色标签“This is the notification."。可用于显示当前app的状态,用户操作的提示等等。 Code4App编译测试...

    Axure交互原型Web组件库 完整版v1.rp

    按纽状态 按纽风格 图标按纽 组合按钮 动态按纽 功能按纽 导航栏 Nav Bar 常用水平导航栏 灰色背景导航栏 暗色背景导航栏 可展开式导航栏 菜单 Menu 常用导航菜单 按纽列表菜单 下拉菜单...

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

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

Global site tag (gtag.js) - Google Analytics