状态栏中的通知
来源:互联网 发布:淘宝假鞋店铺 编辑:程序博客网 时间:2024/05/29 15:32
package com.example.firsst;
import android.os.Bundle;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
private static int notificateID=102;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn=(Button)findViewById(R.id.del);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
notification();
}
});
Button bt=(Button)findViewById(R.id.cancle);
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
notificationCancel();
}
});
}
//发送通知
public void notification()
{
NotificationManager noManager=(NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
//创建状态栏通知
Notification notification=new Notification();
//给状态栏通知设置各种属性
notification.icon=R.drawable.aa;
//通知时在状态栏显示的内容
notification.tickerText="注意了,我被扔到状态栏了";
//设置为当前时间
notification.when=System.currentTimeMillis();
//通知的默认参数 DEFAULT_SOUND, DEFAULT_VIBRATE, DEFAULT_LIGHTS.
//如果要全部采用默认值, 用 DEFAULT_ALL.
//此处采用默认声音
notification.defaults=Notification.DEFAULT_SOUND;
Intent intent=new Intent(this,Other.class);
PendingIntent pIntent=PendingIntent.getActivity(this, 0, intent,0);
//setLatestEventInfo第二个参数 :下拉状态栏时显示的消息标题 expanded message title
//第三个参数:下拉状态栏时显示的消息内容 expanded message text
//第四个参数:点击该通知时执行页面跳转
notification.setLatestEventInfo(this, "测试notification", "测试一下哦", pIntent);
//发出状态栏通知
noManager.notify(notificateID,notification);
}
//清除通知
public void notificationCancel()
{
NotificationManager noManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
noManager.cancel(notificateID);
}
}
01点击第一个图片中的"显示notification"按钮就会显示第二张图片的通知
02
- 状态栏中的通知
- Android中的通知:Toast,对话框,状态栏
- 状态栏通知
- android 状态栏及通知栏中的下载动画效果实现
- Android通知之状态栏通知
- 创建状态栏通知 notification
- android 状态栏 通知
- Android 状态栏通知
- Notification(状态栏通知)
- Notification状态栏通知
- 发送状态栏通知 Notification
- Android 状态栏通知Notification
- Android 状态栏通知
- android 发送状态栏通知
- Android_Notification通知状态栏详解
- 状态栏通知相关
- 【Android】状态栏通知Notification
- Android 状态栏通知详解
- openCV-cvMat数据结构
- opennebula源码分析 -- XML-RPC 原理分析
- 利用Java实现串口全双工通讯
- 构造方法
- 使用JAVA操作netty框架
- 状态栏中的通知
- 使用ant编译android工程
- 抛开IDE编译程序
- mvc设计模式
- Wake学习笔记
- Linux Security Framework -- Apparmor机制介绍
- setBackgroundDrawable与setImageDrawable的区别
- 基于ichartjs图形库在android上使用HTML动态实现多数据源的面积图
- 创建WatermarkTextBox和WatermarkPasswordBox(带水印的文本框)