Java Code Examples for android.app.Notification#DEFAULT_VIBRATE
The following examples show how to use
android.app.Notification#DEFAULT_VIBRATE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProximityIntentReceiver.java From geopaparazzi with GNU General Public License v3.0 | 6 votes |
private static Notification createNotification() { Notification notification = new Notification(); notification.icon = R.drawable.current_position; notification.when = System.currentTimeMillis(); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.defaults |= Notification.DEFAULT_VIBRATE; notification.defaults |= Notification.DEFAULT_LIGHTS; notification.defaults |= Notification.DEFAULT_SOUND; notification.ledARGB = Color.RED; notification.ledOnMS = 1500; notification.ledOffMS = 1500; return notification; }
Example 2
Source File: UpdateService.java From coolreader with MIT License | 6 votes |
@SuppressWarnings("deprecation") public Notification getNotificationTemplate(boolean firstNotification) { int icon = android.R.drawable.arrow_up_float; // Just a placeholder CharSequence tickerText = "New Chapters Update"; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Constants.PREF_PERSIST_NOTIFICATION, false)) { notification.flags = Notification.FLAG_AUTO_CANCEL; } notification.defaults = 0; if (firstNotification) { if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Constants.PREF_UPDATE_RING, false)) { notification.defaults |= Notification.DEFAULT_SOUND; } if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Constants.PREF_UPDATE_VIBRATE, false)) { notification.defaults |= Notification.DEFAULT_VIBRATE; } } return notification; }
Example 3
Source File: NotificationHelper.java From NekoSMS with GNU General Public License v3.0 | 6 votes |
private static void applyNotificationStyle(Context context, Notification notification) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { return; } SharedPreferences prefs = context.getSharedPreferences(PreferenceConsts.FILE_MAIN, Context.MODE_PRIVATE); String ringtone = prefs.getString(PreferenceConsts.KEY_NOTIFICATIONS_RINGTONE, PreferenceConsts.KEY_NOTIFICATIONS_RINGTONE_DEFAULT); if (!TextUtils.isEmpty(ringtone)) { notification.sound = Uri.parse(ringtone); } if (prefs.getBoolean(PreferenceConsts.KEY_NOTIFICATIONS_VIBRATE, PreferenceConsts.KEY_NOTIFICATIONS_VIBRATE_DEFAULT)) { notification.defaults |= Notification.DEFAULT_VIBRATE; } if (prefs.getBoolean(PreferenceConsts.KEY_NOTIFICATIONS_LIGHTS, PreferenceConsts.KEY_NOTIFICATIONS_LIGHTS_DEFAULT)) { notification.defaults |= Notification.DEFAULT_LIGHTS; } String priority = prefs.getString(PreferenceConsts.KEY_NOTIFICATIONS_PRIORITY, PreferenceConsts.KEY_NOTIFICATIONS_PRIORITY_DEFAULT); notification.priority = Integer.parseInt(priority); }
Example 4
Source File: Utils.java From adbwireless with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("deprecation") public static void showNotification(Context context, int icon, String text) { final Notification notifyDetails = new Notification(icon, text, System.currentTimeMillis()); notifyDetails.flags = Notification.FLAG_ONGOING_EVENT; if (prefsSound(context)) { notifyDetails.defaults |= Notification.DEFAULT_SOUND; } if (prefsVibrate(context)) { notifyDetails.defaults |= Notification.DEFAULT_VIBRATE; } Intent notifyIntent = new Intent(context, adbWireless.class); notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notifyIntent, 0); notifyDetails.setLatestEventInfo(context, context.getResources().getString(R.string.noti_title), text, intent); if (Utils.mNotificationManager != null) { Utils.mNotificationManager.notify(Utils.START_NOTIFICATION_ID, notifyDetails); } else { Utils.mNotificationManager = (NotificationManager) context.getSystemService(Activity.NOTIFICATION_SERVICE); } Utils.mNotificationManager.notify(Utils.START_NOTIFICATION_ID, notifyDetails); }
Example 5
Source File: NotificationRecord.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private long[] calculateVibration() { long[] vibration; final long[] defaultVibration = NotificationManagerService.getLongArray( mContext.getResources(), com.android.internal.R.array.config_defaultNotificationVibePattern, NotificationManagerService.VIBRATE_PATTERN_MAXLEN, NotificationManagerService.DEFAULT_VIBRATE_PATTERN); if (getChannel().shouldVibrate()) { vibration = getChannel().getVibrationPattern() == null ? defaultVibration : getChannel().getVibrationPattern(); } else { vibration = null; } if (mPreChannelsNotification && (getChannel().getUserLockedFields() & NotificationChannel.USER_LOCKED_VIBRATION) == 0) { final Notification notification = sbn.getNotification(); final boolean useDefaultVibrate = (notification.defaults & Notification.DEFAULT_VIBRATE) != 0; if (useDefaultVibrate) { vibration = defaultVibration; } else { vibration = notification.vibrate; } } return vibration; }
Example 6
Source File: BaseService.java From VSigner with GNU General Public License v2.0 | 5 votes |
@SuppressLint("NewApi") protected void showNotify(String title, String content, String info, Class<?> jumpClass) { if(!Conf.isNotify) return; Intent intent = new Intent(mContext, jumpClass); PendingIntent pendingIntent = PendingIntent.getActivity(mContext,0,intent,0); //获得通知管理器 NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); //构建一个通知对象(需要传递的参数有三个,分别是图标,标题和 时间) Notification notification = new Notification.Builder(mContext) .setContentText(content) .setContentTitle(title) .setContentInfo(info) .setContentIntent(pendingIntent) .setWhen(System.currentTimeMillis()) .setSmallIcon(R.drawable.ic_launcher) .build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; // 自动销毁 notification.defaults |= Notification.DEFAULT_LIGHTS; if(Conf.isNotifySound) { notification.defaults |= Notification.DEFAULT_SOUND; } if(Conf.isNotifyVibrate) { notification.defaults |= Notification.DEFAULT_VIBRATE; } manager.notify(0, notification);//发动通知,id由自己指定,每一个Notification对应的唯一标志 }
Example 7
Source File: GCMIntentService.java From apigee-android-sdk with Apache License 2.0 | 5 votes |
/** * Issues a Notification to inform the user that server has sent a message. */ private static void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(context, LoginActivity.class); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); Notification notification = new NotificationCompat.Builder(context) .setContentText(message) .setContentTitle(context.getString(R.string.app_name)) .setSmallIcon(icon) .setWhen(when) .setContentIntent(intent) .build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; // Play default notification sound notification.defaults |= Notification.DEFAULT_SOUND; // Vibrate if vibrate is enabled notification.defaults |= Notification.DEFAULT_VIBRATE; notificationManager.notify(0, notification); }
Example 8
Source File: Toggled.java From opentasks with Apache License 2.0 | 5 votes |
@Override public int value() { if (mFlag != Notification.DEFAULT_VIBRATE && mFlag != Notification.DEFAULT_SOUND && mFlag != Notification.DEFAULT_LIGHTS) { throw new IllegalArgumentException("Notification signal flag is not valid: " + mFlag); } return mEnable ? addFlag(mOriginal.value(), mFlag) : removeFlag(mOriginal.value(), mFlag); }
Example 9
Source File: GCMIntentService.java From apigee-android-sdk with Apache License 2.0 | 5 votes |
/** * Issues a Notification to inform the user that server has sent a message. */ private static void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(context, PushMainActivity.class); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); Notification notification = new NotificationCompat.Builder(context) .setContentText(message) .setContentTitle(context.getString(R.string.app_name)) .setSmallIcon(icon) .setWhen(when) .setContentIntent(intent) .build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; // Play default notification sound notification.defaults |= Notification.DEFAULT_SOUND; // Vibrate if vibrate is enabled notification.defaults |= Notification.DEFAULT_VIBRATE; notificationManager.notify(0, notification); }
Example 10
Source File: Notifications.java From Onosendai with Apache License 2.0 | 5 votes |
private static void applyStyle (final Builder nb, final NotificationStyle ns) { int defaults = 0; if (ns.isLights()) defaults |= Notification.DEFAULT_LIGHTS; if (ns.isVibrate()) defaults |= Notification.DEFAULT_VIBRATE; if (ns.isSound()) defaults |= Notification.DEFAULT_SOUND; nb.setDefaults(defaults); }
Example 11
Source File: RLPushHelper.java From Roid-Library with Apache License 2.0 | 5 votes |
/** * @param isDebug */ public void init(boolean isDebug) { JPushInterface.setDebugMode(isDebug); JPushInterface.init(mContext); JPushInterface.setLatestNotifactionNumber(mContext, LASTEST_NOTIFICATION_NUMBER); BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(mContext); builder.notificationFlags = Notification.FLAG_AUTO_CANCEL; builder.notificationDefaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE; builder.developerArg0 = "data"; JPushInterface.setPushNotificationBuilder(1, builder); }
Example 12
Source File: NotifyUtil0.java From NotifyUtil with Apache License 2.0 | 5 votes |
/** * 设置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); }
Example 13
Source File: ReminderService.java From ExpressHelper with GNU General Public License v3.0 | 5 votes |
private static int parseDefaults(Context context) { Settings settings = Settings.getInstance(context); return (settings.getBoolean(Settings.KEY_NOTIFICATION_SOUND, true) ? Notification.DEFAULT_SOUND : 0) | (settings.getBoolean(Settings.KEY_NOTIFICATION_VIBRATE, true) ? Notification.DEFAULT_VIBRATE : 0) | Notification.DEFAULT_LIGHTS; }
Example 14
Source File: NotificationUtil.java From sms-ticket with Apache License 2.0 | 4 votes |
private static void fireNotification(Context c, int notificationId, PendingIntent contentIntent, String title, String text, List<String> rows, String summary, String ticker, int smallIcon, int largeIcon, List<Action> actions, boolean keepNotification) { int defaults = Notification.DEFAULT_LIGHTS; if (Preferences.getBoolean(c, Preferences.NOTIFICATION_VIBRATE, true)) { defaults |= Notification.DEFAULT_VIBRATE; } NotificationCompat.Builder builder = new NotificationCompat.Builder(c).setContentTitle(title).setSmallIcon (smallIcon).setLargeIcon(BitmapFactory.decodeResource(c.getResources(), largeIcon)) .setTicker(ticker).setContentText(text) .setLocalOnly(true) .setContentIntent(contentIntent).setWhen(System.currentTimeMillis()).setAutoCancel(!keepNotification) .setDefaults (defaults); String soundUri = Preferences.getString(c, Preferences.NOTIFICATION_RINGTONE, null); if (!TextUtils.isEmpty(soundUri)) { builder.setSound(Uri.parse(soundUri)); } if (actions != null) { for (Action action : actions) { builder.addAction(action.drawable, c.getString(action.text), action.intent); } } Notification notification; if (rows == null) { notification = builder.build(); } else { NotificationCompat.InboxStyle styled = new NotificationCompat.InboxStyle(builder); for (String row : rows) { styled.addLine(row); } styled.setSummaryText(summary); notification = styled.build(); } NotificationManager nm = (NotificationManager)c.getSystemService(Context.NOTIFICATION_SERVICE); if (nm == null) { DebugLog.e("Cannot obtain notification manager"); return; } nm.notify(notificationId, notification); }
Example 15
Source File: MessageUtil.java From GcmForMojo with GNU General Public License v3.0 | 4 votes |
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 +context.getString(R.string.notify_title_msgcount_new) +")"; } 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) // .setSubText(context.getString(R.string.notification_group_sys_name)) .setAutoCancel(true) .setSound(defaultSoundUri) .setDefaults(defaults) .setContentIntent(pendingIntent) .setDeleteIntent(pendingIntentCancel); notificationBuilder.setPriority(Notification.PRIORITY_HIGH); //自动弹出通知 if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { notificationBuilder.setColor(context.getResources().getColor(R.color.colorPrimary)); } if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { notificationBuilder.setChannelId(context.getString(R.string.notification_channel_sys_id)); } NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(notifyId, notificationBuilder.build()); }
Example 16
Source File: LedSettingsActivity.java From GravityBox with Apache License 2.0 | 4 votes |
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); }
Example 17
Source File: Notifications.java From XMPPSample_Studio with Apache License 2.0 | 4 votes |
public static void showIncomingMessageNotification(Context context, boolean groupChat, String jid, String message, String displayName) { if (context == null) return; SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(context); boolean notification = prefs.getBoolean("notification", true); if (!notification) { return; } NotificationManager nm = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder localBuilder = new NotificationCompat.Builder( context); // messagesFrom.add(StringUtils.parseName(jid)); try { messagesFrom.add(StringUtils.maybeToString((JidCreate.bareFrom(jid).getLocalpartOrNull()))); } catch (XmppStringprepException e) { e.printStackTrace(); } messageNumber++; if (messagesFrom.size() > 1) { localBuilder.setContentTitle(messageNumber + " messages from " + messagesFrom.size() + " users"); } else { if (groupChat) { // String username = StringUtils.parseBareAddress(StringUtils // .parseResource(jid)); // Edited by Saveen 12-July-2016 String username = jid; Log.e("taggi", "groupChat username :" + username); localBuilder.setContentTitle(username + " in group"); } else { localBuilder.setContentTitle(displayName); } } localBuilder.setContentText(message); localBuilder.setSmallIcon(R.drawable.ic_launcher); localBuilder.setLargeIcon(BitmapFactory.decodeResource( context.getResources(), R.drawable.ic_launcher)); localBuilder.setNumber(messageNumber); int defaults = 0; boolean sound = prefs.getBoolean("notificationsound", true); boolean vibrate = prefs.getBoolean("notificationvibrate", true); if (sound) { defaults |= Notification.DEFAULT_SOUND; } if (vibrate) { defaults |= Notification.DEFAULT_VIBRATE; } defaults |= Notification.DEFAULT_LIGHTS; localBuilder.setDefaults(defaults); if (groupChat) { } else { Intent notificationIntent = new Intent(context, ActivityChatScreen.class); if (messagesFrom.size() == 1) { notificationIntent.putExtra("id", jid); Log.e("tag", "notification jid :" + jid); notificationIntent.putExtra( "username", DatabaseHelper.getInstance(context).getDisplayName( context, jid)); } PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); localBuilder.setContentIntent(contentIntent); } nm.notify(10201, localBuilder.build()); }
Example 18
Source File: Vibration.java From opentasks with Apache License 2.0 | 4 votes |
public Vibration(boolean enable, NotificationSignal original) { super(new Toggled(Notification.DEFAULT_VIBRATE, enable, original)); }
Example 19
Source File: DownloadService.java From ESeal with Apache License 2.0 | 4 votes |
/** * 设置下载进度条Notification显示 */ private void setupNotificationDownloading(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); notificationBuilder.setContentIntent(pendingIntent);// 该通知要启动的Intent notificationBuilder.setSmallIcon(smallIcon);// 设置顶部状态栏的小图标 notificationBuilder.setTicker(ticker);// 在顶部状态栏中的提示信息 notificationBuilder.setContentTitle(title);// 设置通知中心的标题 notificationBuilder.setContentText(content);// 设置通知中心中的内容 notificationBuilder.setWhen(System.currentTimeMillis()); /* * 将AutoCancel设为true后,当你点击通知栏的notification后,它会自动被取消消失, * 不设置的话点击消息后也不清除,但可以滑动删除 */ notificationBuilder.setAutoCancel(false); // 将Ongoing设为true 那么notification将不能滑动删除 // notifyBuilder.setOngoing(true); /* * 从Android4.1开始,可以通过以下方法,设置notification的优先级, * 优先级越高的,通知排的越靠前,优先级低的,不会在手机最顶部的状态栏显示图标 */ notificationBuilder.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; } notificationBuilder.setDefaults(defaults); }
Example 20
Source File: NotificationUsageStats.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
public void countApiUse(NotificationRecord record) { final Notification n = record.getNotification(); if (n.actions != null) { numWithActions++; } if ((n.flags & Notification.FLAG_FOREGROUND_SERVICE) != 0) { numForegroundService++; } if ((n.flags & Notification.FLAG_ONGOING_EVENT) != 0) { numOngoing++; } if ((n.flags & Notification.FLAG_AUTO_CANCEL) != 0) { numAutoCancel++; } if ((n.defaults & Notification.DEFAULT_SOUND) != 0 || (n.defaults & Notification.DEFAULT_VIBRATE) != 0 || n.sound != null || n.vibrate != null) { numInterrupt++; } switch (n.visibility) { case Notification.VISIBILITY_PRIVATE: numPrivate++; break; case Notification.VISIBILITY_SECRET: numSecret++; break; } if (record.stats.isNoisy) { noisyImportance.increment(record.stats.requestedImportance); } else { quietImportance.increment(record.stats.requestedImportance); } finalImportance.increment(record.getImportance()); final Set<String> names = n.extras.keySet(); if (names.contains(Notification.EXTRA_BIG_TEXT)) { numWithBigText++; } if (names.contains(Notification.EXTRA_PICTURE)) { numWithBigPicture++; } if (names.contains(Notification.EXTRA_LARGE_ICON)) { numWithLargeIcon++; } if (names.contains(Notification.EXTRA_TEXT_LINES)) { numWithInbox++; } if (names.contains(Notification.EXTRA_MEDIA_SESSION)) { numWithMediaSession++; } if (names.contains(Notification.EXTRA_TITLE) && !TextUtils.isEmpty(n.extras.getCharSequence(Notification.EXTRA_TITLE))) { numWithTitle++; } if (names.contains(Notification.EXTRA_TEXT) && !TextUtils.isEmpty(n.extras.getCharSequence(Notification.EXTRA_TEXT))) { numWithText++; } if (names.contains(Notification.EXTRA_SUB_TEXT) && !TextUtils.isEmpty(n.extras.getCharSequence(Notification.EXTRA_SUB_TEXT))) { numWithSubText++; } if (names.contains(Notification.EXTRA_INFO_TEXT) && !TextUtils.isEmpty(n.extras.getCharSequence(Notification.EXTRA_INFO_TEXT))) { numWithInfoText++; } }