Answer the question
In order to leave comments, you need to log in
Why can't I group notifications?
I can't implement merging notifications into a group. Moreover, notifications stopped stacking when there are 4 or more of them, apparently because I set a new group. But she doesn't work!
Here is my code:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notificationHelper.createChannel(); // созаю канал
notificationHelper
.getManager()
.notify(-271, notificationHelper.createGroup().build()); // создаю группу
}
notificationHelper
.getManager()
.notify(id, notificationHelper.createNotification(id, title, message, icon).build()); // создаю уведомление
@TargetApi(Build.VERSION_CODES.O)
public void createChannel() {
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
channel.enableLights(true);
channel.setLightColor(Color.RED);
channel.setDescription(CHANNEL_DESCRIPTION);
channel.enableVibration(true);
channel.setVibrationPattern(new long[]{0, 1000, 500, 1000});
channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
getManager().createNotificationChannel(channel);
}
public NotificationCompat.Builder createGroup() {
return new NotificationCompat.Builder(getApplicationContext(), "-100")
.setContentInfo(CHANNEL_NAME)
.setSmallIcon(R.drawable.icon_default)
.setChannelId(CHANNEL_ID)
.setGroup(GROUP_KEY)
.setGroupSummary(true);
}
public NotificationCompat.Builder createNotification(int id, String title, String message, int icon) {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), id, intent, PendingIntent.FLAG_CANCEL_CURRENT);
String skill = "Задание";
if (!title.equals("")) {
skill = title;
}
return new NotificationCompat.Builder(getApplicationContext(), String.valueOf(id))
.setDefaults(Notification.DEFAULT_ALL)
.setContentTitle(skill)
.setContentText(message)
.setWhen(System.currentTimeMillis())
.setTicker("Хей, у тебя есть не выполненное задание!")
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setAutoCancel(true)
.setChannelId(CHANNEL_ID)
.setGroup(GROUP_KEY)
.setContentIntent(pendingIntent)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.setSmallIcon(IconHelper.getIcon(icon));
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="kolmachikhin.alexander.todolist">
<uses-permission android:name="android.permission.ACTION_LOCKED_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.SET_ALARM"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
tools:ignore="GoogleAppIndexingWarning">
<activity.../>
<activity.../>
<activity.../>
<activity.../>
<receiver
android:name=".Notification.AlertReceiver"
android:directBootAware="true"
android:enabled="true"
android:exported="false"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED"/>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>
private static final String CHANNEL_NAME = "To do list - name";
private static final String CHANNEL_ID = "To do list - id";
private static final String CHANNEL_DESCRIPTION = "To do list";
private static final String GROUP_KEY = "To do list - group key";
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question