From d501f17525e23478197a69832e59cf1f47d32127 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Fri, 8 Feb 2019 17:18:10 +0100 Subject: [PATCH 1/6] request permission to ask the user to ignore battery-optimize --- AndroidManifest.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index e35d020ee..eaf0d1b66 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -31,6 +31,7 @@ + Date: Fri, 8 Feb 2019 17:19:31 +0100 Subject: [PATCH 2/6] ask the the user to disable battery-optimize if eligible; check the system setting before adding the permanent notification --- .../securesms/ConversationListFragment.java | 13 +++-- .../securesms/LogViewFragment.java | 22 ++++++--- .../components/reminder/DozeReminder.java | 47 ++++++++++++------- .../securesms/connect/KeepAliveService.java | 13 +++++ 4 files changed, 67 insertions(+), 28 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ConversationListFragment.java b/src/org/thoughtcrime/securesms/ConversationListFragment.java index a5e778a5a..49cb885fc 100644 --- a/src/org/thoughtcrime/securesms/ConversationListFragment.java +++ b/src/org/thoughtcrime/securesms/ConversationListFragment.java @@ -58,6 +58,7 @@ import com.b44t.messenger.DcEventCenter; import org.thoughtcrime.securesms.ConversationListAdapter.ItemClickListener; import org.thoughtcrime.securesms.components.recyclerview.DeleteItemAnimator; import org.thoughtcrime.securesms.components.registration.PulsingFloatingActionButton; +import org.thoughtcrime.securesms.components.reminder.DozeReminder; import org.thoughtcrime.securesms.components.reminder.Reminder; import org.thoughtcrime.securesms.components.reminder.ReminderView; import org.thoughtcrime.securesms.connect.ApplicationDcContext; @@ -186,11 +187,13 @@ public class ConversationListFragment extends Fragment // return Optional.of(new ExpiredBuildReminder(context)); // } else if (OutdatedBuildReminder.isEligible()) { // return Optional.of(new OutdatedBuildReminder(context)); -// } else if (DozeReminder.isEligible(context)) { -// return Optional.of(new DozeReminder(context)); -// } else { - return Optional.absent(); -// } +// } else + if (DozeReminder.isEligible(context)) { + return Optional.of(new DozeReminder(context)); + } + else { + return Optional.absent(); + } } @Override diff --git a/src/org/thoughtcrime/securesms/LogViewFragment.java b/src/org/thoughtcrime/securesms/LogViewFragment.java index 3d51a3460..cd67b41dc 100644 --- a/src/org/thoughtcrime/securesms/LogViewFragment.java +++ b/src/org/thoughtcrime/securesms/LogViewFragment.java @@ -26,6 +26,7 @@ import android.os.Build; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.os.Bundle; +import android.os.PowerManager; import android.support.v4.app.Fragment; import android.text.TextUtils; import android.util.Log; @@ -160,21 +161,24 @@ public class LogViewFragment extends Fragment { } private static String buildDescription(Context context) { + + PowerManager powerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); final PackageManager pm = context.getPackageManager(); final StringBuilder builder = new StringBuilder(); - builder.append("Device : ") + builder.append("device=") .append(Build.MANUFACTURER).append(" ") .append(Build.MODEL).append(" (") .append(Build.PRODUCT).append(")\n"); - builder.append("Android : ").append(VERSION.RELEASE).append(" (") + builder.append("android=").append(VERSION.RELEASE).append(" (") .append(VERSION.INCREMENTAL).append(", ") .append(Build.DISPLAY).append(")\n"); - builder.append("Memory : ").append(getMemoryUsage(context)).append("\n"); - builder.append("Memclass: ").append(getMemoryClass(context)).append("\n"); - builder.append("OS Host : ").append(Build.HOST).append("\n"); - builder.append("App : "); + builder.append("sdk=").append(Build.VERSION.SDK_INT).append("\n"); + builder.append("memory=").append(getMemoryUsage(context)).append("\n"); + builder.append("memoryClass=").append(getMemoryClass(context)).append("\n"); + builder.append("host=").append(Build.HOST).append("\n"); + builder.append("app="); try { builder.append(pm.getApplicationLabel(pm.getApplicationInfo(context.getPackageName(), 0))) .append(" ") @@ -183,7 +187,11 @@ public class LogViewFragment extends Fragment { .append(BuildConfig.FLAVOR) .append(BuildConfig.DEBUG? "-debug" : "") .append("\n"); - } catch (PackageManager.NameNotFoundException nnfe) { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + builder.append("ignoreBatteryOptimizations=").append( + powerManager.isIgnoringBatteryOptimizations(context.getPackageName())).append("\n"); + } + } catch (Exception e) { builder.append("Unknown\n"); } diff --git a/src/org/thoughtcrime/securesms/components/reminder/DozeReminder.java b/src/org/thoughtcrime/securesms/components/reminder/DozeReminder.java index 909465354..e0ab84452 100644 --- a/src/org/thoughtcrime/securesms/components/reminder/DozeReminder.java +++ b/src/org/thoughtcrime/securesms/components/reminder/DozeReminder.java @@ -1,15 +1,18 @@ package org.thoughtcrime.securesms.components.reminder; +import android.Manifest; import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager; import android.net.Uri; import android.os.Build; import android.os.PowerManager; import android.provider.Settings; import android.support.annotation.NonNull; import android.support.annotation.RequiresApi; +import android.support.v4.content.ContextCompat; import android.view.View; import org.thoughtcrime.securesms.R; @@ -20,32 +23,44 @@ public class DozeReminder extends Reminder { @RequiresApi(api = Build.VERSION_CODES.M) public DozeReminder(@NonNull final Context context) { - super("R.string.DozeReminder_optimize_for_missing_play_services", - "R.string.DozeReminder_this_device_does_not_support_play_services_tap_to_disable_system_battery"); + super("Tap here to receive messages while Delta Chat is in background.", + "Delta Chat uses minimal resources and takes care not to drain your battery."); setOkListener(v -> { - Prefs.setPromptedOptimizeDoze(context, true); - Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, - Uri.parse("package:" + context.getPackageName())); - context.startActivity(intent); + if(ContextCompat.checkSelfPermission(context, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)==PackageManager.PERMISSION_GRANTED) { + Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, + Uri.parse("package:" + context.getPackageName())); + context.startActivity(intent); + } + else { + Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); + context.startActivity(intent); + } }); - setDismissListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Prefs.setPromptedOptimizeDoze(context, true); - } + setDismissListener(v -> { + Prefs. setPromptedOptimizeDoze(context, true); }); } public static boolean isEligible(Context context) { - if(context!=null) { // condition is always true, disable reminder for now + if(context==null) { return false; } - return !Prefs.hasPromptedOptimizeDoze(context) && - Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && - !((PowerManager)context.getSystemService(Context.POWER_SERVICE)).isIgnoringBatteryOptimizations(context.getPackageName()); - } + if(Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { + return false; + } + if(Prefs.hasPromptedOptimizeDoze(context)) { + return false; + } + + PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE); + if(pm.isIgnoringBatteryOptimizations(context.getPackageName())) { + return false; + } + + return true; // yip, asking for disabling battery optimisations makes sense + } } diff --git a/src/org/thoughtcrime/securesms/connect/KeepAliveService.java b/src/org/thoughtcrime/securesms/connect/KeepAliveService.java index c00f2e26b..7c3444073 100644 --- a/src/org/thoughtcrime/securesms/connect/KeepAliveService.java +++ b/src/org/thoughtcrime/securesms/connect/KeepAliveService.java @@ -7,6 +7,7 @@ import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.IBinder; +import android.os.PowerManager; import android.support.v4.app.NotificationCompat; import android.util.Log; @@ -20,6 +21,18 @@ public class KeepAliveService extends Service { public static void startSelf(Context context) { try { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + PowerManager powerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); + if(powerManager.isIgnoringBatteryOptimizations(context.getPackageName())) { + return; // fine, the user has disabled the battery optimisations for us + } + } + else { + return; // android <= lollipop does not have a doze mode + } + + // if we're here, we're on a system with doze mode and battery optimisations enabled. + // add foreground notification to stay alive. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { // the started service has to call startForeground() within 5 seconds, // see https://developer.android.com/about/versions/oreo/android-8.0-changes From 4866b5ea408088605452abd2a77c6bcbdb08b525 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Sat, 9 Feb 2019 01:20:50 +0100 Subject: [PATCH 3/6] use unique icon for the permanent notification --- res/drawable-hdpi/notification_permanent.png | Bin 0 -> 1203 bytes res/drawable-mdpi/notification_permanent.png | Bin 0 -> 799 bytes res/drawable-xhdpi/notification_permanent.png | Bin 0 -> 1665 bytes res/drawable-xxhdpi/notification_permanent.png | Bin 0 -> 2432 bytes .../securesms/connect/KeepAliveService.java | 2 +- 5 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 res/drawable-hdpi/notification_permanent.png create mode 100644 res/drawable-mdpi/notification_permanent.png create mode 100644 res/drawable-xhdpi/notification_permanent.png create mode 100644 res/drawable-xxhdpi/notification_permanent.png diff --git a/res/drawable-hdpi/notification_permanent.png b/res/drawable-hdpi/notification_permanent.png new file mode 100644 index 0000000000000000000000000000000000000000..a51a0b7246adeaf7c7a9e0c4338f24e5608c7ed4 GIT binary patch literal 1203 zcmV;k1WfyhP)(^b8FWQhbW?9;ba!ELWdL_~cP?peYja~^ zaAhuUa%Y?FJQ@H11TaZNK~z|U&6rJWRYerXfB#o1g*TwBpv-vfy}HCcnIhOW)*dwQ6KO{5wKh!Gg}Qj##C6QnE>a3lDA3u zG~iocm!z?pfy}G~tOxFmIPM011P%kk*|p+l^G2W@SOv@r`kw^0N&2TSkcW8|w^p(m z2i}v^<89i3#s1w1Nyh^}4Zt(Nionkx@J2aq%*>3v`u@K+6f8u9t8 z9HJI#J7_0>Uw{L^VM!y|mp*a64Qv4JEa>w(;7l24aW%_8J-GAe41k%{nb`_lHeLXH zD(S4G5i|P`cmh~k!0&vRnxQ!bIvB7A*jGNg%b>@)BG?i~LO zFtw=b3IOeqv^N9O3cM1)09*^KD>uCT4&ZE#|B)=v#T?^4U|+f6cfMfE=gY%1`5DBaK%_G>jGTD z<+E;}JDc<({ubiy|LwrLlEyFR536Qe?Xv*4Q!W6P(3EQ}DX%S42f^AwTGN4V7mNJV-$3Pl&5*_ojc=y?x_r1@L zi2kel?mg%KKlj{o&f|YZ-0UzjS79@@;9lH;9xmW4<}e!(i~mX>Gke&MUATQnkjprP znTWVNR3J0g;5BS2TURiPlek!X#;_4nxU<+TU~fd69Vk%9-^RMKwSh5Qj0mf$50&8t>!S5TDI3QaVB97xghyQX@;6jJN{)ng_bElQ12+x+@fp2iFb^d!(V4-!GIMMjt&=J5IrQ;*w zVolhlKnk z)yQpPdt?1e2l-q?ER}Wpjpmw>)|gR^g&NOg<`ZST-^zD7gU?I!)0l3FU#b`FaXqOT z3w6%_!dEz0zBj6x>SVEb0oyumHxm(G_6Zb`b*jc`=5z@^;XH1^dQ~rU^$*NP#O_Xk zB66E*9uenSKBIUPt0Us@ dkl_A1{szLZ#!MX?#?Sx&002ovPDHLkV1jWKcAx+N literal 0 HcmV?d00001 diff --git a/res/drawable-xhdpi/notification_permanent.png b/res/drawable-xhdpi/notification_permanent.png new file mode 100644 index 0000000000000000000000000000000000000000..db42c978ca698bcee79a11f63109683b075cd373 GIT binary patch literal 1665 zcmV-{27dX8P);8>i{DOFx|ID13bLN~gGrxrk_iT8I~SJ&owKF_ zRs$;~wdC1V$N@7O3q0(NNy2VmEwEM6=^R}hfT6%mz^y<{3hNeNY2Mk$b->JS17>CL zt^_`kWS+kZZkKujCxK>3r&4rZgxl5ODY_eg#aT{dI^b7+b_U-zNlQF$cie>LrKRH=BNRl1g=h*V=M4lS~zvcFn%a5Y_go(>Ulc>^MPBa42dqdP5r) zkXwq2{UnS5rllE>=zza%=8zuq5h7#jfB`wY-GIlymyCbPopZ1%_3r8{A?%6TKM zI9X75r=+hF=woObGFh0CLjSm+d{Z6GHSE9JA;w8Ng&GXmHcUfZn>_(p4EqR79fO)BevQtd#Gv|1snab~#mycO|! zAnkxg5YQ)qewy-5RD_COoIx2fKT0|j65eu1A#Az5rtgQ3+0(VOl!RiFs z6tW+}W=Y56#0m#|fBr49Z={*NTOG>n2R_Y^iLhQ$eMm5~8*tr_EF@NPiH$8u4Zx}l zWi`MPW_DSOz5=(p6@`qatpeT+iQf1*X|@FDm}qMnw~xuka5+vIjswf$g^Zc?#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&UC}G)?&)Nz5-wNVaxAhf_0G181}) zvj%qJ*_GY+?K>KeUr)p1LuI$?s=P9rZakXe9N-=JLrl62!;Q_q;Pz5s;xpJy)A5tq zbMa!;&O2y7aC0_r*3E~ToDM9;4Z$`GLl5B|_#?nW*#pC|2o)v^aOZZQaC68k>iXkx zLV5qWz#DPHE_K%%h(vC|6AFJ1r7msiI29*rK5$#e%mTywfTdt5zYf3sCWqG~Jbp7K yy!PRd$AQ Date: Sat, 9 Feb 2019 01:33:22 +0100 Subject: [PATCH 4/6] define a notification channel, closes #708 --- .../securesms/connect/KeepAliveService.java | 21 +++++++++++++++++++ .../AbstractNotificationBuilder.java | 18 ++++++++++++++++ .../MultipleRecipientNotificationBuilder.java | 5 +++++ .../SingleRecipientNotificationBuilder.java | 4 ++++ 4 files changed, 48 insertions(+) diff --git a/src/org/thoughtcrime/securesms/connect/KeepAliveService.java b/src/org/thoughtcrime/securesms/connect/KeepAliveService.java index 68babad0e..fcfb818f8 100644 --- a/src/org/thoughtcrime/securesms/connect/KeepAliveService.java +++ b/src/org/thoughtcrime/securesms/connect/KeepAliveService.java @@ -1,6 +1,9 @@ package org.thoughtcrime.securesms.connect; +import android.annotation.TargetApi; import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; import android.content.Context; @@ -107,6 +110,24 @@ public class KeepAliveService extends Service { builder.setWhen(0); builder.setContentIntent(contentIntent); builder.setSmallIcon(R.drawable.notification_permanent); + if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O) { + createFgNotificationChannel(this); + builder.setChannelId(FG_CHANNEL_ID); + } return builder.build(); } + + private static boolean ch_created = false; + private static final String FG_CHANNEL_ID = "dc_foreground_notification_ch"; + @TargetApi(Build.VERSION_CODES.O) + static private void createFgNotificationChannel(Context context) { + if(!ch_created) { + ch_created = true; + NotificationChannel channel = new NotificationChannel(FG_CHANNEL_ID, + "Receive messages in background.", NotificationManager.IMPORTANCE_DEFAULT); + channel.setDescription("Ensure reliable message receiving."); + NotificationManager notificationManager = context.getSystemService(NotificationManager.class); + notificationManager.createNotificationChannel(channel); + } + } } diff --git a/src/org/thoughtcrime/securesms/notifications/AbstractNotificationBuilder.java b/src/org/thoughtcrime/securesms/notifications/AbstractNotificationBuilder.java index d13a0b6b8..71fb00a37 100644 --- a/src/org/thoughtcrime/securesms/notifications/AbstractNotificationBuilder.java +++ b/src/org/thoughtcrime/securesms/notifications/AbstractNotificationBuilder.java @@ -1,9 +1,13 @@ package org.thoughtcrime.securesms.notifications; +import android.annotation.TargetApi; import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; import android.content.Context; import android.graphics.Color; import android.net.Uri; +import android.os.Build; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.NotificationCompat; @@ -86,4 +90,18 @@ public abstract class AbstractNotificationBuilder extends NotificationCompat.Bui return blinkPattern.split(","); } + + private static boolean ch_created = false; + protected static final String MSG_CHANNEL_ID = "dc_message_notification_ch"; + @TargetApi(Build.VERSION_CODES.O) + protected void createMsgNotificationChannel(Context context) { + if(!ch_created) { + ch_created = true; + NotificationChannel channel = new NotificationChannel(MSG_CHANNEL_ID, + "Message notifications", NotificationManager.IMPORTANCE_DEFAULT); + channel.setDescription("Informs about new messages."); + NotificationManager notificationManager = context.getSystemService(NotificationManager.class); + notificationManager.createNotificationChannel(channel); + } + } } diff --git a/src/org/thoughtcrime/securesms/notifications/MultipleRecipientNotificationBuilder.java b/src/org/thoughtcrime/securesms/notifications/MultipleRecipientNotificationBuilder.java index 077efe658..ffdca5fa4 100644 --- a/src/org/thoughtcrime/securesms/notifications/MultipleRecipientNotificationBuilder.java +++ b/src/org/thoughtcrime/securesms/notifications/MultipleRecipientNotificationBuilder.java @@ -4,6 +4,7 @@ import android.app.Notification; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; +import android.os.Build; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.NotificationCompat; @@ -41,6 +42,10 @@ public class MultipleRecipientNotificationBuilder extends AbstractNotificationBu setColor(context.getResources().getColor(R.color.delta_primary)); setSmallIcon(R.drawable.icon_notification); + if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O) { + createMsgNotificationChannel(context); + setChannelId(MSG_CHANNEL_ID); + } setContentTitle(context.getString(R.string.app_name)); setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, ConversationListActivity.class), 0)); setCategory(NotificationCompat.CATEGORY_MESSAGE); diff --git a/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java b/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java index 55fcf32f0..0fedd1c30 100644 --- a/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java +++ b/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java @@ -51,6 +51,10 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil super(context, privacy); setSmallIcon(R.drawable.icon_notification); + if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O) { + createMsgNotificationChannel(context); + setChannelId(MSG_CHANNEL_ID); + } setColor(context.getResources().getColor(R.color.delta_primary)); setPriority(Prefs.getNotificationPriority(context)); setCategory(NotificationCompat.CATEGORY_MESSAGE); From c9fc1c506f5cf482e71e4605e4ea45a668df4c1c Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Sat, 9 Feb 2019 01:44:32 +0100 Subject: [PATCH 5/6] move reminder text to strings.xml --- res/values/strings.xml | 2 ++ .../securesms/components/reminder/DozeReminder.java | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index ec79baba5..706724cdf 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -480,6 +480,8 @@ Delta Chat requires the Microphone permission in order to send audio messages, but it has been permanently denied. Please continue to app settings, select \"Permissions\", and enable \"Microphone\". Delta Chat requires the Storage permission in order to attach or export photos, videos, or audio, but it has been permanently denied. Please continue to the app settings menu, select \"Permissions\", and enable \"Storage\". Delta Chat requires Location permission in order to attach a location, but it has been permanently denied. Please continue to the app settings menu, select \"Permissions\", and enable \"Location\". + Tap here to receive messages while Delta Chat is in background. + Delta Chat uses minimal resources and takes care not to drain your battery. Belgian diff --git a/src/org/thoughtcrime/securesms/components/reminder/DozeReminder.java b/src/org/thoughtcrime/securesms/components/reminder/DozeReminder.java index e0ab84452..9efc77e0a 100644 --- a/src/org/thoughtcrime/securesms/components/reminder/DozeReminder.java +++ b/src/org/thoughtcrime/securesms/components/reminder/DozeReminder.java @@ -23,8 +23,8 @@ public class DozeReminder extends Reminder { @RequiresApi(api = Build.VERSION_CODES.M) public DozeReminder(@NonNull final Context context) { - super("Tap here to receive messages while Delta Chat is in background.", - "Delta Chat uses minimal resources and takes care not to drain your battery."); + super(context.getString(R.string.perm_enable_bg_reminder_title), + context.getString(R.string.perm_enable_bg_reminder_text)); setOkListener(v -> { if(ContextCompat.checkSelfPermission(context, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)==PackageManager.PERMISSION_GRANTED) { From 15a2951b209a17635c37abda4e52b0bab9457510 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Sat, 9 Feb 2019 02:22:56 +0100 Subject: [PATCH 6/6] use min. importance for permanent foreground notification so that no sound is played on oreo, fixes #710 --- src/org/thoughtcrime/securesms/connect/KeepAliveService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/thoughtcrime/securesms/connect/KeepAliveService.java b/src/org/thoughtcrime/securesms/connect/KeepAliveService.java index fcfb818f8..02860b687 100644 --- a/src/org/thoughtcrime/securesms/connect/KeepAliveService.java +++ b/src/org/thoughtcrime/securesms/connect/KeepAliveService.java @@ -124,7 +124,7 @@ public class KeepAliveService extends Service { if(!ch_created) { ch_created = true; NotificationChannel channel = new NotificationChannel(FG_CHANNEL_ID, - "Receive messages in background.", NotificationManager.IMPORTANCE_DEFAULT); + "Receive messages in background.", NotificationManager.IMPORTANCE_MIN); // IMPORTANCE_DEFAULT will play a sound channel.setDescription("Ensure reliable message receiving."); NotificationManager notificationManager = context.getSystemService(NotificationManager.class); notificationManager.createNotificationChannel(channel);