//主要代码
package com.ck;
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.view.View.OnClickListener;
import android.widget.Button;
public class NotificationActivity extends Activity {
private Button button1,button2;
private Notification n;
private NotificationManager nm;
private static final int ID = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button1 = (Button)findViewById(R.id.button1);
button2 = (Button)findViewById(R.id.button2);
nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
n = new Notification();
int icon = n.icon = R.drawable.ic_launcher;
String test = "this is notification speaking,,";
long when = System.currentTimeMillis();
n.icon = icon;
n.tickerText = test;
n.when = when;
button1.setOnClickListener(sendListener);
button2.setOnClickListener(cancelListener);
}
private OnClickListener sendListener = new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(NotificationActivity.this,SecondActivity.class);
PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
n.setLatestEventInfo(getApplicationContext(), "ck", "chenkai", pi);
nm.notify(ID,n);
}
};
private OnClickListener cancelListener = new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
nm.cancel(ID);
}
};
}
分享到:
相关推荐
在Android系统中,发一个状态栏通知还是很方便的。下面我们就来看一下,怎么发送状态栏通知,状态栏通知又有哪些参数可以设置?... NotificationManagernm=(NotificationManager)getSystemService(NOTIFICATION_SERV
首先,发送一个状态栏通知必须用到两个类: NotificationManager 、 Notification。 NotificationManager : 是状态栏通知的管理类,负责发通知、清楚通知等。 NotificationManager 是一个系统Service,必须通过 ...
本文主要讲解状态栏通知Notification、NotificationManager,小编觉得非常详细,给大家一个参考,希望对大家学习有所帮助。
在使用手机时,当有未接来电或者新短消息时,手机会给...使用Notification和NotificationManager类发送和显示通知也比较简单,大致可以分为以下四个步骤 (1)调用getSystemService() 方法获取系统的NotificationManag
在使用手机时,当有未接来电或者是新短消息时,手机会给出...使用Notification和NotificationManager类发送和显示通知也比较简单,大致可分为以下4个步骤。 (1)调用getSystemService()方法获取系统的NotificationManag
关于通知Notification相信大家都不陌生了,平时上QQ的时候有消息来了或者有收到了短信,手机顶部就会显示有新消息什么的,就类似这种。今天就稍微记录下几种Notification...3.0以前的通知和3.0以后的通知是有些区别的。
NULL 博文链接:https://forlan.iteye.com/blog/2264722
android 状态栏的图标与文字提醒 NotificationManager与Notification
这个例子演示Android 在状态栏... NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(0, myNotification);//发送Notification
调用getSystemService(NOTIFICATION_SERVICE)方法获取系统的NotifacationManager服务 通过构造器创建一个Notification对象 为Notification设置各种属性 通过NotificationManager发送Notification。
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(1, notification); or Json2Notification.from(context)....
可以设置一条通知,当然可以更新一条通知,我们通过在调用NotificationManager.notify(ID, notification)时所使用的ID来更新它。为了更新你之前发布的通知,你需要更新或者创建一个NotificationCompat.Builder对象,...
Android界面 NotificationManager使用Bitmap做图标,如何实现呢,本文将介绍解决方法,需要的朋友可以参考下
自学 Android 做的第二十七个 Android 程序,使用了 NotificationManager、Notification 和 Notification.Builder
BroadcastReceiver是全局|系统级别的监听器 Notification和NotificationManager是局部|程序级别的监听器,可以实现可视化的信息显示,通过它在设备状态栏上显示广播信息的内容以及图标和震动等信息
本文实例讲解了通知Notification使用方法,此知识点就是用作通知的显示,包括振动、灯光、声音等效果,分享给大家供大家参考,具体内容如下 效果图: MainActivity: import java.io.File; import android....
notification类表示一个持久的通知,将提交给用户使用NotificationManager。已添加的Notification.Builder,使其更容易构建通知。