Android状态栏通知Status Bar Notification
来源:互联网 发布:linux查看登录用户清单 编辑:程序博客网 时间:2024/05/16 14:44
Android状态栏通知Status Bar Notification
状态栏通知最典型的一种就是当收到短信时会在状态栏上显示一个通知,可
以用鼠标点击状态栏并向下拖动,以查看是否有新的状态栏通知。
文章来源:好岸园it技术网 http://www.hopean.com
strings.xml
<?xml version="1.0" encoding="utf-8"?><resources> <string name="app_name">ANotificationDemo</string> <string name="hello_world">Hello world!</string> <string name="menu_settings">Settings</string><string name="send">发送通知</string></resources>
main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/send"android:id="@+id/button"/></RelativeLayout>
java代码如下
MainActivity.java
package com.example.anotificationdemo;import android.app.Activity;import android.app.Notification;import android.app.NotificationManager;import android.app.PendingIntent;import android.content.Context;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.view.Menu;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button button = (Button)findViewById(R.id.button);button.setOnClickListener(new View.OnClickListener() {@SuppressWarnings("deprecation")@Overridepublic void onClick(View v) {//获取通知管理器NotificationManager mNotificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);int icon = android.R.drawable.sym_action_email;long when = System.currentTimeMillis();//新建一个通知,指定其图标和标题//第一个参数为图标,第二个参数为标题,第三个为通知时间@SuppressWarnings("deprecation")Notification notification = new Notification(icon, null, when);notification.defaults = Notification.DEFAULT_SOUND;//发出默认声音//当点击消息时就会向系统发送 openintent 意图PendingIntent contentIntent = PendingIntent.getActivity(MainActivity.this, 0, null, 0);notification.setLatestEventInfo(MainActivity.this, "通知", "今天下午 5 点全体人员到会议室开会!", contentIntent);mNotificationManager.notify(0, notification);//发送通知}});}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.activity_main, menu);return true;}}
修改完成后就能运行出所要的结果了
源码下载:ANotificationDemo
- Android状态栏通知Status Bar Notification
- android-status bar :状态栏通知
- android学习笔记(14)Status Bar Notification 状态栏、通知栏推送
- Android开发者指南-创建状态栏通知(Status Bar)[原创译文]
- Android自定义状态栏通知(Status Notification)的正确实现
- Android自定义状态栏通知(Status Notification)的正确实现
- Android自定义状态栏通知(Status Notification)的正确实现
- Android自定义状态栏通知(Status Notification)的正确实现
- Android自定义状态栏通知(Status Notification)的正确实现
- Android自定义状态栏通知(Status Notification)的正确实现
- Android自定义状态栏通知(Status Notification)的正确实现
- Android自定义状态栏通知(Status Notification)的正确实现
- android 实现自定义状态栏通知(Status Notification)
- Android自定义状态栏通知(Status Notification)的正确实现
- Android自定义状态栏通知(Status Notification)的正确实现
- Android自定义状态栏通知(Status Notification)的正确实现
- Android自定义状态栏通知(Status Notification)的正确实现
- Notification通知可以显示到系统上方的状态栏(status bar)
- hibernate缓存机制
- Spring 整合Struts
- 与百度大牛的对话
- java 操作 excel 文件
- Ubuntu给Firfox安装Flash插件
- Android状态栏通知Status Bar Notification
- Samba使用简介
- 经典的机器学习方面源代码库
- soj 1796. Max's kingdom
- CKEditor 插件开发:工具栏按钮快速入门
- 蜜果私塾:http协议学习和总结系列——协议详解篇
- 浅谈MySQL表类型
- VC获取系统时间、程序运行时间.
- 蜜果私塾:http协议学习和总结系列--基础概念篇