Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NotificationManager notifManager = null;
- final int NOTIFY_ID = 0; // ID of notification
- String id = "12345qwerty"; // default_channel_id
- String channelTitle = "qwerty"; // Default Channel
- Intent intent;
- PendingIntent pendingIntent;
- NotificationCompat.Builder builder;
- notifManager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- int importance = NotificationManager.IMPORTANCE_HIGH;
- NotificationChannel mChannel = notifManager.getNotificationChannel(id);
- if (mChannel == null) {
- mChannel = new NotificationChannel(id, channelTitle, importance);
- mChannel.enableVibration(true);
- mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
- notifManager.createNotificationChannel(mChannel);
- }
- builder = new NotificationCompat.Builder(this, id);
- intent = new Intent(this, MainActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
- pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
- builder.setContentTitle(body) // required
- .setSmallIcon(R.drawable.ic_code_black_24dp) // required
- .setContentText(this.getString(R.string.app_name)) // required
- .setDefaults(Notification.DEFAULT_ALL)
- .setAutoCancel(true)
- .setContentIntent(pendingIntent)
- .setTicker(body)
- .setVibrate(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
- }
- else {
- builder = new NotificationCompat.Builder(this, id);
- intent = new Intent(this, MainActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
- pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
- builder.setContentTitle(body) // required
- .setSmallIcon(R.drawable.ic_code_black_24dp) // required
- .setContentText(this.getString(R.string.app_name)) // required
- .setDefaults(Notification.DEFAULT_ALL)
- .setAutoCancel(true)
- .setContentIntent(pendingIntent)
- .setTicker(body)
- .setVibrate(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400})
- .setPriority(Notification.PRIORITY_HIGH);
- }
- Notification notification = builder.build();
- notifManager.notify(NOTIFY_ID, notification);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement