Android Notification之监听系统清除通知栏方法
来源:互联网 发布:5233软件下载 编辑:程序博客网 时间:2024/06/04 19:27
编写了一个Notification通知工具类,里面含有监听系统清除通知栏方法,焦点在加粗斜体部分:
public class Notifier {
private static final String TAG = Notifier.class.getSimpleName();
private static Notifier instance;
private Context mContext;
private static final int NOTIFICATION_ID_1 = 0;
private static final int NOTIFICATION_ID_2 = 1;
private static final int NOTIFICATION_ID_3 = 2;
private static final int NOTIFICATION_ID_4 = 3;
private static final int NOTIFICATION_ID_5 = 4;
private static final int NOTIFICATION_ID_6 = 5;
private static final int NOTIFICATION_ID_7 = 6;
private static final int NOTIFICATION_ID_8 = 7;
public static Notifier getInstance(Context context) {
if (instance == null) {
instance = new Notifier(context);
}
return instance;
}
public Notifier(Context context) {
mContext = context;
}
public NotificationManager getNotificationManager(Context context) {
return (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
}
public void showNotify(Context context, int largeIcon, int smallIcon,
CharSequence tickerText, CharSequence contentInfo,
CharSequence contentTitle, CharSequence contentText) {
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent(context, MainActivity.class), 0);
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),
largeIcon);
NotificationCompat.Builder notifyBuilder = new NotificationCompat.Builder(
context);
// notifyBuilder.setLargeIcon(bitmap);
notifyBuilder.setSmallIcon(smallIcon);
notifyBuilder.setTicker(tickerText);
notifyBuilder.setContentInfo(contentInfo);
notifyBuilder.setContentTitle(contentTitle);
notifyBuilder.setContentText(contentText);
notifyBuilder.setAutoCancel(false);
notifyBuilder.setWhen(System.currentTimeMillis());
notifyBuilder.setDefaults(Notification.DEFAULT_ALL);
notifyBuilder.setContentIntent(contentIntent);
Notification noti = notifyBuilder.build();
getNotificationManager(context).notify(NOTIFICATION_ID_1, noti);
}
public void showCustomViewNotify(Context context, int smallIcon,
CharSequence tickerText, int layoutId) {
RemoteViews mRemoteViews = new RemoteViews(context.getPackageName(),
layoutId);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent(context, MainActivity.class), 0);
NotificationCompat.Builder notifyBuilder = new NotificationCompat.Builder(
context);
notifyBuilder.setSmallIcon(smallIcon);
notifyBuilder.setContent(mRemoteViews);
notifyBuilder.setTicker(tickerText);
notifyBuilder.setOngoing(true);
notifyBuilder.setAutoCancel(true);
notifyBuilder.setDefaults(Notification.DEFAULT_ALL);
notifyBuilder.setContentIntent(contentIntent);
Notification noti = notifyBuilder.build();
Intent dismissedIntent = new Intent(
"com.xxxx.android.notify.dismissed");
/**
* The intent to execute when the notification is explicitly dismissed
* by the user, either with the "Clear All" button or by swiping it away
* individually.
*
* This probably shouldn't be launching an activity since several of
* those will be sent at the same time.
*/
noti.deleteIntent = PendingIntent.getBroadcast(context, 0,
dismissedIntent, 0);
getNotificationManager(context).notify(NOTIFICATION_ID_2, noti);
}
public Notification getForegroundServiceNotify(Context context,
int smallIcon, CharSequence tickerText, CharSequence contentInfo,
CharSequence contentTitle, CharSequence contentText) {
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent(context, MainActivity.class), 0);
NotificationCompat.Builder notifyBuilder = new NotificationCompat.Builder(
context);
notifyBuilder.setSmallIcon(smallIcon);
notifyBuilder.setTicker(tickerText);
notifyBuilder.setContentInfo(contentInfo);
notifyBuilder.setContentTitle(contentTitle);
notifyBuilder.setContentText(contentText);
notifyBuilder.setAutoCancel(false);
notifyBuilder.setContentIntent(contentIntent);
// notifyBuilder.setWhen(System.currentTimeMillis());
notifyBuilder.setDefaults(Notification.DEFAULT_ALL);
return notifyBuilder.build();
}
}
- Android Notification之监听系统清除通知栏方法
- android之Notification监听系统清除通知栏
- Android 之 Notification通知栏
- Android系统服务之Notification(通知栏消息)
- Android系统通知Notification
- android之Notification通知
- android之Notification通知
- android之Notification通知
- android之Notification通知
- android之Notification通知
- android之Notification通知
- Android之Notification通知
- android之Notification通知
- android之Notification通知
- android之Notification通知
- Android--通知之Notification
- android--通知之Notification
- android之Notification通知
- android:fastScrollEnabled和android:drawSelectorOnTop
- 线程----BlockingQueue (转)
- 好莱坞艳照门女星曝光 奥斯卡影后詹妮弗劳伦斯艳照流出
- android:点击popupwindow以外区域 popupwindow自动消失
- JAVA 动态替换代理IP并模拟POST请求
- Android Notification之监听系统清除通知栏方法
- 笔记系列1
- QML类型说明-CompassReading
- MySkin仿QQ皮肤,零基础拥有漂亮的软件界面
- Django学习第一天
- java 泛型应用
- VB.NET基础 字符串相关的函数
- java中hashCode的作用
- centos配置tomcat