本文整理汇总了Java中android.app.Notification.DEFAULT_LIGHTS属性的典型用法代码示例。如果您正苦于以下问题:Java Notification.DEFAULT_LIGHTS属性的具体用法?Java Notification.DEFAULT_LIGHTS怎么用?Java Notification.DEFAULT_LIGHTS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.app.Notification
的用法示例。
在下文中一共展示了Notification.DEFAULT_LIGHTS属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addCustomNotification
public void addCustomNotification(Intent onClickIntent, int iconResourceID, String title, String message, boolean isOngoingEvent) {
PendingIntent notifContentIntent = PendingIntent.getActivity(this, 0, onClickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Bitmap bm = null;
try {
bm = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
} catch (Exception e) {
}
mCustomNotif = Compatibility.createNotification(this, title, message, iconResourceID, 0, bm, notifContentIntent, isOngoingEvent,notifcationsPriority);
mCustomNotif.defaults |= Notification.DEFAULT_VIBRATE;
mCustomNotif.defaults |= Notification.DEFAULT_SOUND;
mCustomNotif.defaults |= Notification.DEFAULT_LIGHTS;
notifyWrapper(CUSTOM_NOTIF_ID, mCustomNotif);
}
示例2: makeNotification
private Notification makeNotification(PendingIntent pendingIntent, String title, String content, String tickerText,
int iconId, boolean ring, boolean vibrate) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setContentTitle(title)
.setContentText(content)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setTicker(tickerText)
.setSmallIcon(iconId);
int defaults = Notification.DEFAULT_LIGHTS;
if (vibrate) {
defaults |= Notification.DEFAULT_VIBRATE;
}
if (ring) {
defaults |= Notification.DEFAULT_SOUND;
}
builder.setDefaults(defaults);
return builder.build();
}
示例3: makeNotification
private Notification makeNotification(PendingIntent pendingIntent, String title, String content, String tickerText,
int iconId, boolean ring, boolean vibrate) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setContentTitle(title)
.setContentText(content)
.setTicker(content)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setTicker(tickerText)
.setLargeIcon(largeIconId())
.setSmallIcon(iconId);
int defaults = Notification.DEFAULT_LIGHTS;
if (vibrate) {
defaults |= Notification.DEFAULT_VIBRATE;
}
if (ring) {
defaults |= Notification.DEFAULT_SOUND;
}
builder.setDefaults(defaults);
return builder.build();
}
示例4: applyLed
private void applyLed(Notification notification) {
if (ledColor == LedColor.OFF) {
notification.ledARGB = 0;
} else if (ledColor == LedColor.DEFAULT) {
notification.defaults |= Notification.DEFAULT_LIGHTS;
enableLights(notification);
} else {
notification.ledARGB = ledColor.color;
enableLights(notification);
}
}
示例5: setBuilder
/**
* 设置builder的信息,在用大文本时会用到这个
*
* @param pendingIntent
* @param smallIcon
* @param ticker
*/
private void setBuilder(PendingIntent pendingIntent, int smallIcon, String ticker, boolean sound, boolean vibrate, boolean lights) {
nBuilder = new Notification.Builder(mContext);
// 如果当前Activity启动在前台,则不开启新的Activity。
// intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
// PendingIntent pIntent = PendingIntent.getActivity(mContext,
// requestCode, intent, FLAG);
nBuilder.setContentIntent(pendingIntent);
nBuilder.setSmallIcon(smallIcon);
nBuilder.setTicker(ticker);
nBuilder.setWhen(System.currentTimeMillis());
nBuilder.setPriority(Notification.PRIORITY_MAX);
int defaults = 0;
if (sound) {
defaults |= Notification.DEFAULT_SOUND;
}
if (vibrate) {
defaults |= Notification.DEFAULT_VIBRATE;
}
if (lights) {
defaults |= Notification.DEFAULT_LIGHTS;
}
nBuilder.setDefaults(defaults);
}
示例6: setCompatBuilder
/**
* 设置在顶部通知栏中的各种信息
*
* @param pendingIntent
* @param smallIcon
* @param ticker
* @param pendingIntentCancel
*/
private void setCompatBuilder(PendingIntent pendingIntent, int smallIcon, String ticker,
String title, String content, boolean sound, boolean vibrate, boolean lights, PendingIntent pendingIntentCancel) {
// // 如果当前Activity启动在前台,则不开启新的Activity。
// intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
// // 当设置下面PendingIntent.FLAG_UPDATE_CURRENT这个参数的时候,常常使得点击通知栏没效果,你需要给notification设置一个独一无二的requestCode
// // 将Intent封装进PendingIntent中,点击通知的消息后,就会启动对应的程序
// PendingIntent pIntent = PendingIntent.getActivity(mContext,
// requestCode, intent, FLAG);
cBuilder.setContentIntent(pendingIntent);// 该通知要启动的Intent
cBuilder.setSmallIcon(smallIcon);// 设置顶部状态栏的小图标
cBuilder.setTicker(ticker);// 在顶部状态栏中的提示信息
cBuilder.setContentTitle(title);// 设置通知中心的标题
cBuilder.setContentText(content);// 设置通知中心中的内容
cBuilder.setWhen(System.currentTimeMillis());
/*
* 将AutoCancel设为true后,当你点击通知栏的notification后,它会自动被取消消失,
* 不设置的话点击消息后也不清除,但可以滑动删除
*/
cBuilder.setAutoCancel(true);
// 将Ongoing设为true 那么notification将不能滑动删除
// notifyBuilder.setOngoing(true);
/*
* 从Android4.1开始,可以通过以下方法,设置notification的优先级,
* 优先级越高的,通知排的越靠前,优先级低的,不会在手机最顶部的状态栏显示图标
*/
cBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
/*
* Notification.DEFAULT_ALL:铃声、闪光、震动均系统默认。
* Notification.DEFAULT_SOUND:系统默认铃声。
* Notification.DEFAULT_VIBRATE:系统默认震动。
* Notification.DEFAULT_LIGHTS:系统默认闪光。
* notifyBuilder.setDefaults(Notification.DEFAULT_ALL);
*/
int defaults = 0;
cBuilder.setDeleteIntent(pendingIntentCancel);
if (sound) {
defaults |= Notification.DEFAULT_SOUND;
}
if (vibrate) {
defaults |= Notification.DEFAULT_VIBRATE;
}
if (lights) {
defaults |= Notification.DEFAULT_LIGHTS;
}
cBuilder.setDefaults(defaults);
}
示例7: setCompatBuilder
/**
* 设置在顶部通知栏中的各种信息
* @param pendingIntent
* @param smallIcon
* @param ticker
* @param pendingIntentCancel
*/
private void setCompatBuilder(PendingIntent pendingIntent, int smallIcon, String ticker,
String title, String content, boolean sound, boolean vibrate, boolean lights, PendingIntent pendingIntentCancel) {
// // 如果当前Activity启动在前台,则不开启新的Activity。
// intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
// // 当设置下面PendingIntent.FLAG_UPDATE_CURRENT这个参数的时候,常常使得点击通知栏没效果,你需要给notification设置一个独一无二的requestCode
// // 将Intent封装进PendingIntent中,点击通知的消息后,就会启动对应的程序
// PendingIntent pIntent = PendingIntent.getActivity(mContext,
// requestCode, intent, FLAG);
cBuilder.setContentIntent(pendingIntent);// 该通知要启动的Intent
cBuilder.setSmallIcon(smallIcon);// 设置顶部状态栏的小图标
cBuilder.setTicker(ticker);// 在顶部状态栏中的提示信息
cBuilder.setContentTitle(title);// 设置通知中心的标题
cBuilder.setContentText(content);// 设置通知中心中的内容
cBuilder.setWhen(System.currentTimeMillis());
/*
* 将AutoCancel设为true后,当你点击通知栏的notification后,它会自动被取消消失,
* 不设置的话点击消息后也不清除,但可以滑动删除
*/
cBuilder.setAutoCancel(true);
// 将Ongoing设为true 那么notification将不能滑动删除
// notifyBuilder.setOngoing(true);
/*
* 从Android4.1开始,可以通过以下方法,设置notification的优先级,
* 优先级越高的,通知排的越靠前,优先级低的,不会在手机最顶部的状态栏显示图标
*/
cBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
/*
* Notification.DEFAULT_ALL:铃声、闪光、震动均系统默认。
* Notification.DEFAULT_SOUND:系统默认铃声。
* Notification.DEFAULT_VIBRATE:系统默认震动。
* Notification.DEFAULT_LIGHTS:系统默认闪光。
* notifyBuilder.setDefaults(Notification.DEFAULT_ALL);
*/
int defaults = 0;
cBuilder.setDeleteIntent(pendingIntentCancel);
if (sound) {
defaults |= Notification.DEFAULT_SOUND;
}
if (vibrate) {
defaults |= Notification.DEFAULT_VIBRATE;
}
if (lights) {
defaults |= Notification.DEFAULT_LIGHTS;
}
cBuilder.setDefaults(defaults);
}
示例8: sendNotificationSys
private static void sendNotificationSys(Context context, String msgTitle, String msgBody, String msgId, int notifyId, int msgCount)
{
Intent intent = new Intent(context, CurrentUserActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Bundle msgListBundle = new Bundle();
msgListBundle.putString("userName", msgTitle);
msgListBundle.putString("userId", msgId);
msgListBundle.putString("userType", SYS);
msgListBundle.putString("userMessage", msgBody);
msgListBundle.putString("userTime", getCurTime());
msgListBundle.putString("senderType", "1");
msgListBundle.putInt("notifyId", notifyId);
msgListBundle.putString("msgCount", String.valueOf(msgCount));
intent.putExtras(msgListBundle);
PendingIntent pendingIntent = PendingIntent.getActivity(context, notifyId /* Request code */, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
Bundle msgNotifyBundle = new Bundle();
msgNotifyBundle.putInt("notifyId", notifyId);
//通知清除事件
Intent intentCancel = new Intent(context, SysNotificationBroadcastReceiver.class);
intentCancel.setAction("sys_notification_cancelled");
intentCancel.putExtras(msgNotifyBundle);
PendingIntent pendingIntentCancel = PendingIntent.getBroadcast(context, notifyId, intentCancel, PendingIntent.FLAG_ONE_SHOT);
StringBuffer tickerSys = new StringBuffer();
tickerSys.append(msgTitle);
tickerSys.append("\r\n");
tickerSys.append(msgBody);
if (msgCount != 1)
{
msgTitle = msgTitle + "(" + msgCount + "条新消息)";
}
int smallIcon;
Bitmap largeIcon;
switch (msgId) {
case "1":
smallIcon = R.drawable.qq_notification;
largeIcon = BitmapFactory.decodeResource(context.getResources(), R.mipmap.qq);
break;
case "2":
smallIcon = R.drawable.weixin_notification;
largeIcon = BitmapFactory.decodeResource(context.getResources(), R.mipmap.weixin);
break;
default:
smallIcon = R.drawable.sys_notification;
largeIcon = BitmapFactory.decodeResource(context.getResources(), R.mipmap.sys);
}
int defaults = 0;
defaults |= Notification.DEFAULT_LIGHTS;
defaults |= Notification.DEFAULT_VIBRATE;
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(smallIcon)
.setLargeIcon(largeIcon)
.setTicker(tickerSys)
.setContentTitle(msgTitle)
.setStyle(new NotificationCompat.BigTextStyle() // 设置通知样式为大型文本样式
.bigText(msgBody))
.setContentText(msgBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setDefaults(defaults)
.setContentIntent(pendingIntent)
.setDeleteIntent(pendingIntentCancel);
notificationBuilder.setPriority(Notification.PRIORITY_HIGH); //自动弹出通知
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notifyId, notificationBuilder.build());
}
示例9: previewSettings
private void previewSettings() {
Notification.Builder builder = new Notification.Builder(this)
.setContentTitle(getString(R.string.lc_preview_notif_title))
.setContentText(String.format(Locale.getDefault(),
getString(R.string.lc_preview_notif_text), getTitle()))
.setSmallIcon(R.drawable.ic_notif_gravitybox)
.setLargeIcon(Icon.createWithResource(this, R.drawable.ic_launcher));
final Notification n = builder.build();
if (mPrefsFragment.getLedMode() == LedMode.OFF) {
n.defaults &= ~Notification.DEFAULT_LIGHTS;
n.flags &= ~Notification.FLAG_SHOW_LIGHTS;
} else if (mPrefsFragment.getLedMode() == LedMode.OVERRIDE) {
n.defaults &= ~Notification.DEFAULT_LIGHTS;
n.flags |= Notification.FLAG_SHOW_LIGHTS;
n.ledARGB = mPrefsFragment.getColor();
n.ledOnMS = mPrefsFragment.getLedOnMs();
n.ledOffMS = mPrefsFragment.getLedOffMs();
}
if (mPrefsFragment.getSoundOverride() && mPrefsFragment.getSoundUri() != null) {
n.defaults &= ~Notification.DEFAULT_SOUND;
n.sound = mPrefsFragment.getSoundUri();
}
if (mPrefsFragment.getInsistent()) {
n.flags |= Notification.FLAG_INSISTENT;
}
if (mPrefsFragment.getVibrateOverride()) {
try {
long[] pattern = LedSettings.parseVibratePatternString(
mPrefsFragment.getVibratePatternAsString());
n.defaults &= ~Notification.DEFAULT_VIBRATE;
n.vibrate = pattern;
} catch (Exception e) {
Toast.makeText(this, getString(R.string.lc_vibrate_pattern_invalid),
Toast.LENGTH_SHORT).show();
}
}
if (mPrefsFragment.getVisibility() != Visibility.DEFAULT) {
n.visibility = mPrefsFragment.getVisibility().getValue();
}
if (mPrefsFragment.getVisibilityLs() != VisibilityLs.DEFAULT) {
n.extras.putString(ModLedControl.NOTIF_EXTRA_VISIBILITY_LS,
mPrefsFragment.getVisibilityLs().toString());
}
n.extras.putBoolean("gbIgnoreNotification", true);
Intent intent = new Intent(ModHwKeys.ACTION_SLEEP);
sendBroadcast(intent);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(++NOTIF_ID, n);
}
}, 1000);
}
示例10: build
public void build(){
cBuilder = new NotificationCompat.Builder(NotifyUtil.getInstance().getContext());
cBuilder.setContentIntent(contentIntent);// 该通知要启动的Intent
if(smallIcon >0){
cBuilder.setSmallIcon(smallIcon);// 设置顶部状态栏的小图标
}
if(bigIcon >0){
cBuilder.setLargeIcon(BitmapFactory.decodeResource(NotifyUtil.getInstance().getContext().getResources(), bigIcon));
}
cBuilder.setTicker(ticker);// 在顶部状态栏中的提示信息
cBuilder.setContentTitle(contentTitle);// 设置通知中心的标题
if(!TextUtils.isEmpty(contentText)){
cBuilder.setContentText(contentText);// 设置通知中心中的内容
}
cBuilder.setWhen(System.currentTimeMillis());
//cBuilder.setStyle()
/*
* 将AutoCancel设为true后,当你点击通知栏的notification后,它会自动被取消消失,
* 不设置的话点击消息后也不清除,但可以滑动删除
*/
cBuilder.setAutoCancel(true);
// 将Ongoing设为true 那么notification将不能滑动删除
// notifyBuilder.setOngoing(true);
/*
* 从Android4.1开始,可以通过以下方法,设置notification的优先级,
* 优先级越高的,通知排的越靠前,优先级低的,不会在手机最顶部的状态栏显示图标
*/
cBuilder.setPriority(priority);
//int defaults = 0;
if (sound) {
defaults |= Notification.DEFAULT_SOUND;
}
if (vibrate) {
defaults |= Notification.DEFAULT_VIBRATE;
}
if (lights) {
defaults |= Notification.DEFAULT_LIGHTS;
}
cBuilder.setDefaults(defaults);
//按钮
if(btnActionBeens!=null && btnActionBeens.size()>0){
for(BtnActionBean bean: btnActionBeens){
cBuilder.addAction(bean.icon,bean.text,bean.pendingIntent);
}
}
//headup
if(headup){
cBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
cBuilder.setDefaults(NotificationCompat.DEFAULT_ALL);
}else {
cBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
cBuilder.setDefaults(NotificationCompat.DEFAULT_LIGHTS);
}
if(TextUtils.isEmpty(ticker)){
cBuilder.setTicker("你有新的消息");
}
cBuilder.setOngoing(onGoing);
cBuilder.setFullScreenIntent(fullscreenIntent,true);
cBuilder.setVisibility(lockScreenVisiablity);
}
示例11: getBaseNotificationCompatBuilder
private static NotificationCompat.Builder getBaseNotificationCompatBuilder(JSONObject gcmBundle) {
int notificationIcon = getSmallIconId(gcmBundle);
int notificationDefaults = 0;
String message = gcmBundle.optString("message");
NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(currentContext).setAutoCancel(true)
.setSmallIcon(notificationIcon) // Small Icon required or notification doesn't display
.setContentTitle(gcmBundle.optString("title"))
.setStyle(new NotificationCompat.BigTextStyle().bigText(gcmBundle.optString("message")))
.setContentText(message)
.setTicker(message);
try {
notifBuilder.setLights(0xFFfa3c1a, 2000, 3000);
} catch (Throwable t) {
notificationDefaults |= Notification.DEFAULT_LIGHTS;
} // Can throw if an old android support lib is used or parse error.
Bitmap largeIcon = getLargeIcon(gcmBundle);
if (largeIcon != null) {
notifBuilder.setLargeIcon(largeIcon);
}
Bitmap bigPictureIcon = getBitmap(gcmBundle.optString("mediaUrl", null));
if (bigPictureIcon != null) {
notifBuilder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bigPictureIcon)
.setSummaryText(message));
}
if (isSoundEnabled(gcmBundle)) {
Uri soundUri = getCustomSound(gcmBundle);
if (soundUri != null) {
notifBuilder.setSound(soundUri);
} else {
notificationDefaults |= Notification.DEFAULT_SOUND;
}
}
notificationDefaults |= Notification.DEFAULT_VIBRATE;
notifBuilder.setDefaults(notificationDefaults);
return notifBuilder;
}
示例12: setCompatBuilder
/**
* 设置在顶部通知栏中的各种信息
*
* @param pendingIntent
* @param smallIcon
* @param ticker
*/
private void setCompatBuilder(PendingIntent pendingIntent, int smallIcon, String ticker,
String title, String content, boolean sound, boolean vibrate, boolean lights) {
// // 如果当前Activity启动在前台,则不开启新的Activity。
// intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
// // 当设置下面PendingIntent.FLAG_UPDATE_CURRENT这个参数的时候,常常使得点击通知栏没效果,你需要给notification设置一个独一无二的requestCode
// // 将Intent封装进PendingIntent中,点击通知的消息后,就会启动对应的程序
// PendingIntent pIntent = PendingIntent.getActivity(mContext,
// requestCode, intent, FLAG);
cBuilder.setContentIntent(pendingIntent);// 该通知要启动的Intent
cBuilder.setSmallIcon(smallIcon);// 设置顶部状态栏的小图标
cBuilder.setTicker(ticker);// 在顶部状态栏中的提示信息
cBuilder.setContentTitle(title);// 设置通知中心的标题
cBuilder.setContentText(content);// 设置通知中心中的内容
cBuilder.setWhen(System.currentTimeMillis());
/*
* 将AutoCancel设为true后,当你点击通知栏的notification后,它会自动被取消消失,
* 不设置的话点击消息后也不清除,但可以滑动删除
*/
cBuilder.setAutoCancel(true);
// 将Ongoing设为true 那么notification将不能滑动删除
// notifyBuilder.setOngoing(true);
/*
* 从Android4.1开始,可以通过以下方法,设置notification的优先级,
* 优先级越高的,通知排的越靠前,优先级低的,不会在手机最顶部的状态栏显示图标
*/
cBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
/*
* Notification.DEFAULT_ALL:铃声、闪光、震动均系统默认。
* Notification.DEFAULT_SOUND:系统默认铃声。
* Notification.DEFAULT_VIBRATE:系统默认震动。
* Notification.DEFAULT_LIGHTS:系统默认闪光。
* notifyBuilder.setDefaults(Notification.DEFAULT_ALL);
*/
int defaults = 0;
if (sound) {
defaults |= Notification.DEFAULT_SOUND;
}
if (vibrate) {
defaults |= Notification.DEFAULT_VIBRATE;
}
if (lights) {
defaults |= Notification.DEFAULT_LIGHTS;
}
cBuilder.setDefaults(defaults);
}