@RequiresApi(21) private void sendNotification(Context context, String message, String detail) { initializeWithContext(context); if(this.mNotificationsEnabled) { NotificationCompat.Builder builder = (new NotificationCompat.Builder(context, "err")) .setContentTitle("BluetoothMedic: " + message) .setSmallIcon(mNotificationIcon) .setVibrate(new long[]{200L, 100L, 200L}).setContentText(detail); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addNextIntent(new Intent("NoOperation")); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent( 0, PendingIntent.FLAG_UPDATE_CURRENT ); builder.setContentIntent(resultPendingIntent); NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); if (notificationManager != null) { notificationManager.notify(1, builder.build()); } } }
.setSmallIcon(R.drawable.ic_lawnchair) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setVibrate(new long[]{0, 100, 100, 100}) .setAutoCancel(true) .setContentIntent(pendingIntent);
private Notification createNotification(Activity activity) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID) .setContentIntent(createContentPendingIntent()) .setTicker("") .setSmallIcon(R.drawable.hype_logo) .setOngoing(true) .setVibrate(new long[]{0}); String contentTitle = getString(R.string.hype_notification_content_title); String contentText = getString(R.string.hype_notification_content_text); String subText = getString(R.string.hype_notification_subtext); if (Build.VERSION.SDK_INT == Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { builder.setContentTitle(contentTitle); builder.setContentText(contentText.isEmpty() ? subText : contentText); } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { builder.setContentTitle(contentTitle); builder.setContentText(contentText); builder.setSubText(subText); } else { builder.setContentTitle(contentTitle.isEmpty() ? null : contentTitle); builder.setContentText(contentText.isEmpty() ? null : contentText); builder.setSubText(subText); } return builder.build(); }
@NonNull @Override public android.app.Notification onCreateNotification(Context context) { Intent intent = new Intent(context, UpdateDownloadService.class); intent.setData(downloadUri); PendingIntent pendingIntent = PendingIntentCompat.getForegroundService(context, intent); return new NotificationCompat.Builder(context, UpdateNotificationChannel.ID) .setSmallIcon(R.drawable.ic_stat_hentoid) .setPriority(NotificationCompat.PRIORITY_MAX) .setCategory(NotificationCompat.CATEGORY_MESSAGE) .setVibrate(new long[]{1, 1, 1}) .setContentTitle("Update download failed") .setContentText("Tap to retry") .setContentIntent(pendingIntent) .build(); } }
public static void showNotification(String title, String content, PendingIntent intent, int notificationId, String channelId, boolean sound, boolean vibrate, PendingIntent deleteIntent, Uri sound_uri, String bigmsg) { final NotificationCompat.Builder mBuilder = notificationBuilder(title, content, intent, channelId); final long[] vibratePattern = {0, 1000, 300, 1000, 300, 1000}; if (vibrate) mBuilder.setVibrate(vibratePattern); if (deleteIntent != null) mBuilder.setDeleteIntent(deleteIntent); mBuilder.setLights(0xff00ff00, 300, 1000); if (sound) { Uri soundUri = (sound_uri != null) ? sound_uri : RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(soundUri); } if (bigmsg != null) { mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(bigmsg)); } final NotificationManager mNotifyMgr = (NotificationManager) xdrip.getAppContext().getSystemService(Context.NOTIFICATION_SERVICE); // if (!onetime) mNotifyMgr.cancel(notificationId); mNotifyMgr.notify(notificationId, XdripNotificationCompat.build(mBuilder)); }
public static void sendNotification(Context context, String info){ NotificationCompat.Builder notifyBuilder = new NotificationCompat.Builder(context); //title notifications notifyBuilder.setContentTitle(context.getString(R.string.app_name)); //small icon notifyBuilder.setSmallIcon(R.drawable.ic_launcher); //set contentText notifyBuilder.setContentText(info); notifyBuilder.setVibrate(new long[]{100, 200, 100, 500}); notifyBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); //setAutoCancel notifyBuilder.setAutoCancel(true); getNotificationManager(context).notify(0, notifyBuilder.build()); } public final static NotificationManager getNotificationManager(Context context) { return (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); }
@NonNull @Override public android.app.Notification onCreateNotification(Context context) { Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE, apkUri); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); return new NotificationCompat.Builder(context, UpdateNotificationChannel.ID) .setSmallIcon(R.drawable.ic_stat_hentoid) .setPriority(NotificationCompat.PRIORITY_MAX) .setCategory(NotificationCompat.CATEGORY_MESSAGE) .setVibrate(new long[]{1, 1, 1}) .setContentTitle("Update ready") .setContentText("Tap to install") .setContentIntent(pendingIntent) .build(); } }
public class TimerReceiver extends BroadcastReceiver { private static final int NOTIFICATION = 3456; /*since you're always doing a 1-time notification, we can make this final and static, the number won't change. If you want it to change, consider using SharedPreferences or similar to keep track of the number. You would have the same issue with a Service since you call stopself() and so, you would delete the object every time.*/ @Override public void onReceive(Context context,Intent intent) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(R.drawable.clock_alarm); builder.setContentTitle("Time is up"); builder.setContentText("SLIMS"); builder.setVibrate(new long[] { 0, 200, 100, 200 }); final Notification notification = builder.build(); mNM.notify(NOTIFICATION, notification); }
@NonNull @Override public android.app.Notification onCreateNotification(Context context) { Intent intent = UpdateDownloadService.makeIntent(context, updateUrl); PendingIntent pendingIntent = PendingIntentCompat.getForegroundService(context, intent); return new NotificationCompat.Builder(context, UpdateNotificationChannel.ID) .setSmallIcon(R.drawable.ic_stat_hentoid) .setPriority(NotificationCompat.PRIORITY_MAX) .setCategory(NotificationCompat.CATEGORY_MESSAGE) .setVibrate(new long[]{1, 1, 1}) .setContentTitle("An update is available!") .setContentText("Tap to download") .setContentIntent(pendingIntent) .build(); } }
/** 初始化通知栏 */ public void createProgressNotify(int icon,int notify_id,String tickerText,String title,String content,Intent intent) { notifyId = notify_id; mBuilder = new NotificationCompat.Builder(context,"default"); mBuilder.setSound(null); mBuilder.setVibrate(null); PendingIntent pendingIntent = PendingIntent.getActivity(context, notify_id, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = mBuilder.setWhen(System.currentTimeMillis())// 通知产生的时间,会在通知信息里显示 .setContentIntent(pendingIntent) .setPriority(Notification.PRIORITY_DEFAULT) .setOngoing(false) .setTicker(tickerText) .setSmallIcon(icon) .setContentTitle(title) .setTicker(content);// 通知首次出现在通知栏,带上升动画效果的; }
public NotificationCompat.Builder buildNotificationbelowM(Context context) { final Bundle extras = new Bundle(); extras.putString("android.substName", context.getString(R.string.app_name)); final Intent intent = new Intent(Intent.ACTION_MAIN) .setClass(context, NekoLand.class) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); return new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.stat_icon) .setContentTitle(OldService.notificationText) .setContentText(getName()) .setContentIntent(PendingIntent.getActivity(context, 0, intent, 0)) .setAutoCancel(true) .setVibrate(PURR); }
private void calibrationNotificationCreate(String title, String content, Intent intent, int notificationId) { NotificationCompat.Builder mBuilder = notificationBuilder(title, content, intent, NotificationChannels.CALIBRATION_CHANNEL); mBuilder.setVisibility(Pref.getBooleanDefaultFalse("public_notifications") ? Notification.VISIBILITY_PUBLIC : Notification.VISIBILITY_PRIVATE); mBuilder.setVibrate(vibratePattern); mBuilder.setLights(0xff00ff00, 300, 1000); if(calibration_override_silent) { mBuilder.setSound(Uri.parse(calibration_notification_sound), AudioAttributes.USAGE_ALARM); } else { mBuilder.setSound(Uri.parse(calibration_notification_sound)); } NotificationManager mNotifyMgr = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); //mNotifyMgr.cancel(notificationId); mNotifyMgr.notify(notificationId, XdripNotificationCompat.build(mBuilder)); }
private void calibrationNotificationCreate(String title, String content, Intent intent, int notificationId) { NotificationCompat.Builder mBuilder = notificationBuilder(title, content, intent, NotificationChannels.CALIBRATION_CHANNEL); mBuilder.setVisibility(Pref.getBooleanDefaultFalse("public_notifications") ? Notification.VISIBILITY_PUBLIC : Notification.VISIBILITY_PRIVATE); mBuilder.setVibrate(vibratePattern); mBuilder.setLights(0xff00ff00, 300, 1000); if(calibration_override_silent) { mBuilder.setSound(Uri.parse(calibration_notification_sound), AudioAttributes.USAGE_ALARM); } else { mBuilder.setSound(Uri.parse(calibration_notification_sound)); } NotificationManager mNotifyMgr = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); //mNotifyMgr.cancel(notificationId); mNotifyMgr.notify(notificationId, XdripNotificationCompat.build(mBuilder)); }
private void calibrationNotificationCreate(String title, String content, Intent intent, int notificationId) { NotificationCompat.Builder mBuilder = notificationBuilder(title, content, intent); mBuilder.setVibrate(vibratePattern); mBuilder.setLights(0xff00ff00, 300, 1000); if(calibration_override_silent) { mBuilder.setSound(Uri.parse(calibration_notification_sound), AudioAttributes.USAGE_ALARM); } else { mBuilder.setSound(Uri.parse(calibration_notification_sound)); } NotificationManager mNotifyMgr = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); //mNotifyMgr.cancel(notificationId); mNotifyMgr.notify(notificationId, mBuilder.build()); }
public SimpleNotificationBuilder setVibrate(long[] pattern) { mBuilder.setVibrate(pattern); return this; }
private void setVibrateForNotification() { mNotificationBuilder.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000}); }
public NotificationBuilder setVibration(long[] pattern) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { if (pattern == null || pattern.length == 0) { mBuilder.setVibrate(mVibrate_pattern); } else { mBuilder.setVibrate(pattern); } } return this; }
public NotificationUtil setVibrate(long[] vibrates) { ncBuilder.setVibrate(vibrates); return this; }
@Override public Builder setVibrate(long[] pattern) { super.setVibrate(pattern); return this; }
error_notif.setVibrate(new long[]{500, 500}); handshake_notif.setVibrate(new long[]{500, 500});