Added custom option to keep missed call notif upon app restart

This commit is contained in:
Sylvain Berfini 2019-11-14 15:21:03 +01:00
parent c8d5582ecc
commit 76262573a6
4 changed files with 32 additions and 1 deletions

View file

@ -23,6 +23,7 @@ import android.annotation.TargetApi;
import android.app.NotificationManager;
import android.content.Context;
import android.os.PowerManager;
import android.service.notification.StatusBarNotification;
import org.linphone.contacts.ContactsManager;
import org.linphone.contacts.LinphoneContact;
import org.linphone.core.Address;
@ -111,4 +112,8 @@ class ApiTwentyThreePlus {
return true;
}
public static StatusBarNotification[] getActiveNotifications(NotificationManager manager) {
return manager.getActiveNotifications();
}
}

View file

@ -22,6 +22,7 @@ package org.linphone.compatibility;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.bluetooth.BluetoothAdapter;
import android.content.ContentProviderClient;
@ -30,6 +31,7 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Build;
import android.provider.Settings;
import android.service.notification.StatusBarNotification;
import org.linphone.core.Address;
import org.linphone.mediastream.Version;
import org.linphone.notifications.Notifiable;
@ -309,4 +311,12 @@ public class Compatibility {
}
return null;
}
public static StatusBarNotification[] getActiveNotifications(NotificationManager manager) {
if (Version.sdkAboveOrEqual(Version.API23_MARSHMALLOW_60)) {
return ApiTwentyThreePlus.getActiveNotifications(manager);
}
return new StatusBarNotification[0];
}
}

View file

@ -29,6 +29,7 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.service.notification.StatusBarNotification;
import java.io.File;
import java.util.HashMap;
import org.linphone.LinphoneManager;
@ -84,7 +85,19 @@ public class NotificationsManager {
mCurrentChatRoomAddress = null;
mNM = (NotificationManager) mContext.getSystemService(NOTIFICATION_SERVICE);
mNM.cancelAll();
if (mContext.getResources().getBoolean(R.bool.keep_missed_call_notification_upon_restart)) {
StatusBarNotification[] notifs = Compatibility.getActiveNotifications(mNM);
if (notifs != null && notifs.length > 1) {
for (StatusBarNotification notif : notifs) {
if (notif.getId() != MISSED_CALLS_NOTIF_ID) {
dismissNotification(notif.getId());
}
}
}
} else {
mNM.cancelAll();
}
mLastNotificationId = 5; // Do not conflict with hardcoded notifications ids !

View file

@ -132,6 +132,9 @@
<integer name="notification_ms_on">1000</integer>
<integer name="notification_ms_off">7000</integer>
<!-- Only for Android >= 23 -->
<bool name="keep_missed_call_notification_upon_restart">false</bool>
<!-- Inapp -->
<bool name="enable_in_app_purchase">false</bool>
<!-- Notification shown before end of trial version in days -->