1、通知使用时的api,主要的api,还有一些自定义显示VIew的内容。
Notification.Builder builder = new Notification.Builder(context); 通知创建过程
builder.setContentIntent(pendingIntent) 通知点击事件
.setContentTitle(ticker) 通知设置显示头部的title
.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis()) 通知设置时间
.setSmallIcon(R.drawable.stat_notify_mms) 通知设置默认logo不能为空(在状态栏显示的通知图标,不能为null)
.setContentText(content) 通知设置详情显示
.addAction(actionBuilder.build()) 通知设置按钮动作
.setVisibility(Notification.VISIBILITY_PUBLIC) 通知可见
.setAutoCancel(false); 自动消除
if (currentAvatar == null){
builder.setLargeIcon(defaultAvatar); 设置左侧默认图标(根据不同的ROM厂商提供的通知样式不同显示位置不同)
}else {
currentAvatar = zoomDrawable(context,currentAvatar, defaultAvatar.getWidth(), defaultAvatar.getHeight());
builder.setLargeIcon(currentAvatar);
}
builder.setVibrate(new long[]{0});
builder.setColor(0x6dbf36);
builder.setPriority(Notification.PRIORITY_MAX); 设置悬浮窗,这里可以使用setFullScreenIntent和设置Notification.PRIORITY_HIGH,其中setfullScreenIntent是使用是会在锁屏和resent界面调起对应的界面
builder.setCategory(Notification.CATEGORY_MESSAGE);
int defaults = 0;
Bundle extras = new Bundle();
boolean smsFlag = Settings.System.getInt(context.getContentResolver(), Settings.System.LEUI_NOTIFICATION_PULSE_SECTION2, 1) != 0;
extras.putBoolean(Notification.EXTRA_PRIVILEGE_SHOWING_LIGHT, smsFlag);
defaults |= Notification.DEFAULT_LIGHTS;
if (LeUiMessagingPreferenceActivity.getLightScreenEnable(context)) {
extras.putBoolean(Notification.EXTRA_ENABLE_NOTIFICATION_TURNING_ON, true);
}
builder.setExtras(extras);
builder.setDefaults(defaults);
Intent deleteIntent = new Intent();
deleteIntent.setAction(XYPushEventReceiver.DELETE_ACTION);
deleteIntent.putExtra("serviceId",notificationChannel);
builder.setDeleteIntent(PendingIntent.getBroadcast(context,notificationChannel,deleteIntent,0)); 通知删除时会调用发出这个对应的通知
notification = builder.build();
if (isInCall()) {
builder.setSound(ringtoneStr, AUDIO_ATTRIBUTES_ALARM); 声音设置
} else {
notification.sound = ringtoneStr;
}
if (notificationManager == null) {
notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
}
notificationManager.notify(notificationChannel, notification); 通知发出的api。
2、通知点击显示使用的penddingIntent
Intent[] intent = createIntent(context, notificationInfo,iMessage);
int notificationChannel = Integer.parseInt(iMessage.getAddress());
PendingIntent pendingIntent = PendingIntent.getActivities(context, Integer.parseInt(iMessage.getAddress()), intent,
PendingIntent.FLAG_UPDATE_CURRENT);
pendingIntent 这个方式是开启界面
PendingIntent.getBroadcast(context, UUID.randomUUID().hashCode(), markIntent, PendingIntent.FLAG_UPDATE_CURRENT) 这个方式是发送通知
这里的intent对象就是Android的通用对象。