Fix notifiction on Android O + set color on API >= 21 < 26
This commit is contained in:
parent
a67d0a6f51
commit
887d9310c0
6 changed files with 179 additions and 41 deletions
|
@ -12,6 +12,7 @@
|
|||
<color name="colorJ">#ffa645</color>
|
||||
<color name="colorK">#3eb5c0</color>
|
||||
<color name="colorL">#96c11f</color>
|
||||
<color name="notification_color_led">#FF8000</color>
|
||||
|
||||
<color name="transparent">#00000000</color>
|
||||
</resources>
|
||||
|
|
|
@ -94,6 +94,8 @@
|
|||
<bool name="enable_call_notification">true</bool>
|
||||
<bool name="kill_service_with_task_manager">true</bool>
|
||||
<string name="notification_channel_id">linphone_notification_id</string>
|
||||
<integer name="notification_ms_on">1000</integer>
|
||||
<integer name="notification_ms_off">7000</integer>
|
||||
|
||||
<!-- Tutorial settings -->
|
||||
<bool name="show_tutorials_instead_of_app">false</bool> <!-- Be careful ! Setting this to true prevent the app from working ! It will only display tutorial activities -->
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.linphone.core.LinphoneCore.GlobalState;
|
|||
import org.linphone.core.LinphoneCore.RegistrationState;
|
||||
import org.linphone.core.LinphoneCoreException;
|
||||
import org.linphone.core.LinphoneCoreFactory;
|
||||
import org.linphone.core.LinphoneCoreFactoryImpl;
|
||||
import org.linphone.core.LinphoneCoreListenerBase;
|
||||
import org.linphone.core.LinphoneProxyConfig;
|
||||
import org.linphone.mediastream.Log;
|
||||
|
@ -314,6 +313,7 @@ public final class LinphoneService extends Service {
|
|||
|
||||
mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
mNM.cancel(INCALL_NOTIF_ID); // in case of crash the icon is not removed
|
||||
Compatibility.CreateChannel(this);
|
||||
|
||||
Intent notifIntent = new Intent(this, incomingReceivedActivity);
|
||||
notifIntent.putExtra("Notification", true);
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.app.Notification;
|
|||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
|
||||
/*
|
||||
|
@ -50,8 +51,12 @@ public class ApiTwentyOnePlus {
|
|||
.setSmallIcon(R.drawable.topbar_chat_notification)
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(intent)
|
||||
.setDefaults(Notification.DEFAULT_ALL)
|
||||
.setDefaults(Notification.DEFAULT_SOUND
|
||||
| Notification.DEFAULT_VIBRATE)
|
||||
.setLargeIcon(contactIcon)
|
||||
.setLights(ContextCompat.getColor(context, R.color.notification_color_led),
|
||||
context.getResources().getInteger(R.integer.notification_ms_on),
|
||||
context.getResources().getInteger(R.integer.notification_ms_off))
|
||||
.setCategory(Notification.CATEGORY_MESSAGE)
|
||||
.setVisibility(Notification.VISIBILITY_PRIVATE)
|
||||
.setPriority(Notification.PRIORITY_HIGH)
|
||||
|
@ -74,6 +79,9 @@ public class ApiTwentyOnePlus {
|
|||
.setCategory(Notification.CATEGORY_CALL)
|
||||
.setVisibility(Notification.VISIBILITY_PUBLIC)
|
||||
.setPriority(Notification.PRIORITY_HIGH)
|
||||
.setLights(ContextCompat.getColor(context, R.color.notification_color_led),
|
||||
context.getResources().getInteger(R.integer.notification_ms_on),
|
||||
context.getResources().getInteger(R.integer.notification_ms_off))
|
||||
.build();
|
||||
|
||||
return notif;
|
||||
|
@ -91,6 +99,9 @@ public class ApiTwentyOnePlus {
|
|||
.setContentIntent(intent)
|
||||
.setCategory(Notification.CATEGORY_SERVICE)
|
||||
.setVisibility(Notification.VISIBILITY_SECRET)
|
||||
.setLights(ContextCompat.getColor(context, R.color.notification_color_led),
|
||||
context.getResources().getInteger(R.integer.notification_ms_on),
|
||||
context.getResources().getInteger(R.integer.notification_ms_off))
|
||||
.setPriority(priority)
|
||||
.build();
|
||||
} else {
|
||||
|
@ -101,6 +112,9 @@ public class ApiTwentyOnePlus {
|
|||
.setContentIntent(intent)
|
||||
.setCategory(Notification.CATEGORY_SERVICE)
|
||||
.setVisibility(Notification.VISIBILITY_SECRET)
|
||||
.setLights(ContextCompat.getColor(context, R.color.notification_color_led),
|
||||
context.getResources().getInteger(R.integer.notification_ms_on),
|
||||
context.getResources().getInteger(R.integer.notification_ms_off))
|
||||
.setPriority(priority)
|
||||
.build();
|
||||
}
|
||||
|
@ -119,9 +133,13 @@ public class ApiTwentyOnePlus {
|
|||
.setSmallIcon(R.drawable.call_status_missed)
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(intent)
|
||||
.setDefaults(Notification.DEFAULT_ALL)
|
||||
.setDefaults(Notification.DEFAULT_SOUND
|
||||
| Notification.DEFAULT_VIBRATE)
|
||||
.setCategory(Notification.CATEGORY_MESSAGE)
|
||||
.setVisibility(Notification.VISIBILITY_PRIVATE)
|
||||
.setLights(ContextCompat.getColor(context, R.color.notification_color_led),
|
||||
context.getResources().getInteger(R.integer.notification_ms_on),
|
||||
context.getResources().getInteger(R.integer.notification_ms_off))
|
||||
.setPriority(Notification.PRIORITY_HIGH)
|
||||
.build();
|
||||
|
||||
|
@ -135,9 +153,13 @@ public class ApiTwentyOnePlus {
|
|||
.setSmallIcon(R.drawable.linphone_logo)
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(intent)
|
||||
.setDefaults(Notification.DEFAULT_ALL)
|
||||
.setDefaults(Notification.DEFAULT_SOUND
|
||||
| Notification.DEFAULT_VIBRATE)
|
||||
.setCategory(Notification.CATEGORY_MESSAGE)
|
||||
.setVisibility(Notification.VISIBILITY_PRIVATE)
|
||||
.setLights(ContextCompat.getColor(context, R.color.notification_color_led),
|
||||
context.getResources().getInteger(R.integer.notification_ms_on),
|
||||
context.getResources().getInteger(R.integer.notification_ms_off))
|
||||
.setPriority(Notification.PRIORITY_HIGH)
|
||||
.build();
|
||||
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
package org.linphone.compatibility;
|
||||
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.widget.TextView;
|
||||
import android.annotation.TargetApi;
|
||||
import android.view.ViewTreeObserver;
|
||||
|
||||
import org.linphone.R;
|
||||
|
||||
/*
|
||||
ApiTwentyThreePlus.java
|
||||
ApiTwentyOnePlus.java
|
||||
Copyright (C) 2017 Belledonne Communications, Grenoble, France
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
|
@ -27,11 +30,28 @@ You should have received a copy of the GNU General Public License
|
|||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author Erwan Croze
|
||||
*/
|
||||
@TargetApi(26)
|
||||
public class ApiTwentySixPlus {
|
||||
|
||||
public static void CreateChannel(Context context) {
|
||||
NotificationManager notificationManager =
|
||||
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
String id = context.getString(R.string.notification_channel_id);
|
||||
CharSequence name = context.getString(R.string.content_title_notification);
|
||||
String description = context.getString(R.string.content_title_notification);
|
||||
int importance = NotificationManager.IMPORTANCE_HIGH;
|
||||
NotificationChannel mChannel = new NotificationChannel(id, name, importance);
|
||||
mChannel.setDescription(description);
|
||||
mChannel.enableLights(true);
|
||||
mChannel.setLightColor(context.getColor(R.color.notification_color_led));
|
||||
mChannel.enableLights(true);
|
||||
notificationManager.createNotificationChannel(mChannel);
|
||||
}
|
||||
|
||||
public static Notification createMessageNotification(Context context,
|
||||
int msgCount, String msgSender, String msg, Bitmap contactIcon,
|
||||
PendingIntent intent) {
|
||||
|
@ -39,23 +59,111 @@ public class ApiTwentySixPlus {
|
|||
if (msgCount == 1) {
|
||||
title = msgSender;
|
||||
} else {
|
||||
title = context.getString(R.string.unread_messages)
|
||||
.replace("%i", String.valueOf(msgCount));
|
||||
title = context.getString(R.string.unread_messages).replace("%i", String.valueOf(msgCount));
|
||||
}
|
||||
|
||||
Notification notif = new Notification.Builder(context)
|
||||
.setContentTitle(title)
|
||||
NotificationManager notificationManager =
|
||||
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
Notification notif = null;
|
||||
notif = new Notification.Builder(context, context.getString(R.string.notification_channel_id))
|
||||
.setContentTitle(title)
|
||||
.setContentText(msg)
|
||||
.setSmallIcon(R.drawable.topbar_chat_notification)
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(intent)
|
||||
.setDefaults(Notification.DEFAULT_SOUND
|
||||
| Notification.DEFAULT_VIBRATE)
|
||||
.setLargeIcon(contactIcon)
|
||||
.setCategory(Notification.CATEGORY_MESSAGE)
|
||||
.setVisibility(Notification.VISIBILITY_PRIVATE)
|
||||
.setPriority(Notification.PRIORITY_HIGH)
|
||||
.setNumber(msgCount)
|
||||
.build();
|
||||
|
||||
return notif;
|
||||
}
|
||||
|
||||
public static Notification createInCallNotification(Context context,
|
||||
String title, String msg, int iconID, Bitmap contactIcon,
|
||||
String contactName, PendingIntent intent) {
|
||||
|
||||
Notification notif = new Notification.Builder(context, context.getString(R.string.notification_channel_id))
|
||||
.setContentTitle(contactName)
|
||||
.setContentText(msg)
|
||||
.setSmallIcon(R.drawable.topbar_chat_notification)
|
||||
.setSmallIcon(iconID)
|
||||
.setAutoCancel(false)
|
||||
.setContentIntent(intent)
|
||||
.setLargeIcon(contactIcon)
|
||||
.setCategory(Notification.CATEGORY_CALL)
|
||||
.setVisibility(Notification.VISIBILITY_PUBLIC)
|
||||
.setPriority(Notification.PRIORITY_HIGH)
|
||||
.build();
|
||||
|
||||
return notif;
|
||||
}
|
||||
|
||||
public static Notification createNotification(Context context, String title, String message, int icon, int level, Bitmap largeIcon, PendingIntent intent, boolean isOngoingEvent,int priority) {
|
||||
Notification notif;
|
||||
|
||||
if (largeIcon != null) {
|
||||
notif = new Notification.Builder(context, context.getString(R.string.notification_channel_id))
|
||||
.setContentTitle(title)
|
||||
.setContentText(message)
|
||||
.setSmallIcon(icon, level)
|
||||
.setLargeIcon(largeIcon)
|
||||
.setContentIntent(intent)
|
||||
.setCategory(Notification.CATEGORY_SERVICE)
|
||||
.setVisibility(Notification.VISIBILITY_SECRET)
|
||||
.setPriority(priority)
|
||||
.build();
|
||||
} else {
|
||||
notif = new Notification.Builder(context, context.getString(R.string.notification_channel_id))
|
||||
.setContentTitle(title)
|
||||
.setContentText(message)
|
||||
.setSmallIcon(icon, level)
|
||||
.setContentIntent(intent)
|
||||
.setCategory(Notification.CATEGORY_SERVICE)
|
||||
.setVisibility(Notification.VISIBILITY_SECRET)
|
||||
.setPriority(priority)
|
||||
.build();
|
||||
}
|
||||
|
||||
return notif;
|
||||
}
|
||||
|
||||
public static void removeGlobalLayoutListener(ViewTreeObserver viewTreeObserver, ViewTreeObserver.OnGlobalLayoutListener keyboardListener) {
|
||||
viewTreeObserver.removeOnGlobalLayoutListener(keyboardListener);
|
||||
}
|
||||
|
||||
public static Notification createMissedCallNotification(Context context, String title, String text, PendingIntent intent) {
|
||||
Notification notif = new Notification.Builder(context, context.getString(R.string.notification_channel_id))
|
||||
.setContentTitle(title)
|
||||
.setContentText(text)
|
||||
.setSmallIcon(R.drawable.call_status_missed)
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(intent)
|
||||
.setDefaults(
|
||||
Notification.DEFAULT_LIGHTS
|
||||
| Notification.DEFAULT_SOUND
|
||||
| Notification.DEFAULT_VIBRATE)
|
||||
.setWhen(System.currentTimeMillis())
|
||||
.setLargeIcon(contactIcon)
|
||||
.setNumber(msgCount)
|
||||
.setDefaults(Notification.DEFAULT_SOUND
|
||||
| Notification.DEFAULT_VIBRATE)
|
||||
.setCategory(Notification.CATEGORY_MESSAGE)
|
||||
.setVisibility(Notification.VISIBILITY_PRIVATE)
|
||||
.setPriority(Notification.PRIORITY_HIGH)
|
||||
.build();
|
||||
|
||||
return notif;
|
||||
}
|
||||
|
||||
public static Notification createSimpleNotification(Context context, String title, String text, PendingIntent intent) {
|
||||
Notification notif = new Notification.Builder(context, context.getString(R.string.notification_channel_id))
|
||||
.setContentTitle(title)
|
||||
.setContentText(text)
|
||||
.setSmallIcon(R.drawable.linphone_logo)
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(intent)
|
||||
.setDefaults(Notification.DEFAULT_SOUND
|
||||
| Notification.DEFAULT_VIBRATE)
|
||||
.setCategory(Notification.CATEGORY_MESSAGE)
|
||||
.setVisibility(Notification.VISIBILITY_PRIVATE)
|
||||
.setPriority(Notification.PRIORITY_HIGH)
|
||||
.build();
|
||||
|
||||
return notif;
|
||||
|
|
|
@ -36,57 +36,62 @@ import android.widget.TextView;
|
|||
* @author Sylvain Berfini
|
||||
*/
|
||||
public class Compatibility {
|
||||
public static void CreateChannel(Context context) {
|
||||
if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
|
||||
ApiTwentySixPlus.CreateChannel(context);
|
||||
}
|
||||
}
|
||||
public static Notification createSimpleNotification(Context context, String title, String text, PendingIntent intent) {
|
||||
Notification notif = null;
|
||||
if (Version.sdkAboveOrEqual(Version.API21_LOLLIPOP_50)) {
|
||||
if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
|
||||
return ApiTwentySixPlus.createSimpleNotification(context, title, text, intent);
|
||||
} else if (Version.sdkAboveOrEqual(Version.API21_LOLLIPOP_50)) {
|
||||
return ApiTwentyOnePlus.createSimpleNotification(context, title, text, intent);
|
||||
} else if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) {
|
||||
notif = ApiSixteenPlus.createSimpleNotification(context, title, text, intent);
|
||||
return ApiSixteenPlus.createSimpleNotification(context, title, text, intent);
|
||||
} else {
|
||||
notif = ApiElevenPlus.createSimpleNotification(context, title, text, intent);
|
||||
return ApiElevenPlus.createSimpleNotification(context, title, text, intent);
|
||||
}
|
||||
return notif;
|
||||
}
|
||||
public static Notification createMissedCallNotification(Context context, String title, String text, PendingIntent intent) {
|
||||
Notification notif = null;
|
||||
if (Version.sdkAboveOrEqual(Version.API21_LOLLIPOP_50)) {
|
||||
if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
|
||||
return ApiTwentySixPlus.createMissedCallNotification(context, title, text, intent);
|
||||
} else if (Version.sdkAboveOrEqual(Version.API21_LOLLIPOP_50)) {
|
||||
return ApiTwentyOnePlus.createMissedCallNotification(context, title, text, intent);
|
||||
} else if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) {
|
||||
notif = ApiSixteenPlus.createMissedCallNotification(context, title, text, intent);
|
||||
} else {
|
||||
notif = ApiElevenPlus.createMissedCallNotification(context, title, text, intent);
|
||||
return ApiSixteenPlus.createMissedCallNotification(context, title, text, intent);
|
||||
} else {
|
||||
return ApiElevenPlus.createMissedCallNotification(context, title, text, intent);
|
||||
}
|
||||
return notif;
|
||||
}
|
||||
|
||||
public static Notification createMessageNotification(Context context, int msgCount,String to, String msgSender, String msg, Bitmap contactIcon, PendingIntent intent) {
|
||||
Notification notif = null;
|
||||
if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
|
||||
|
||||
return ApiTwentySixPlus.createMessageNotification(context, msgCount, msgSender, msg, contactIcon, intent);
|
||||
} else if (Version.sdkAboveOrEqual(Version.API21_LOLLIPOP_50)) {
|
||||
return ApiTwentyOnePlus.createMessageNotification(context, msgCount, msgSender, msg, contactIcon, intent);
|
||||
} else if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) {
|
||||
notif = ApiSixteenPlus.createMessageNotification(context, msgCount, msgSender, msg, contactIcon, intent);
|
||||
return ApiSixteenPlus.createMessageNotification(context, msgCount, msgSender, msg, contactIcon, intent);
|
||||
} else {
|
||||
notif = ApiElevenPlus.createMessageNotification(context, msgCount, msgSender, msg, contactIcon, intent);
|
||||
return ApiElevenPlus.createMessageNotification(context, msgCount, msgSender, msg, contactIcon, intent);
|
||||
}
|
||||
return notif;
|
||||
}
|
||||
|
||||
public static Notification createInCallNotification(Context context, String title, String msg, int iconID, Bitmap contactIcon, String contactName, PendingIntent intent) {
|
||||
Notification notif = null;
|
||||
if (Version.sdkAboveOrEqual(Version.API21_LOLLIPOP_50)) {
|
||||
if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
|
||||
return ApiTwentySixPlus.createInCallNotification(context, title, msg, iconID, contactIcon, contactName, intent);
|
||||
} else if (Version.sdkAboveOrEqual(Version.API21_LOLLIPOP_50)) {
|
||||
return ApiTwentyOnePlus.createInCallNotification(context, title, msg, iconID, contactIcon, contactName, intent);
|
||||
} else if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) {
|
||||
notif = ApiSixteenPlus.createInCallNotification(context, title, msg, iconID, contactIcon, contactName, intent);
|
||||
return ApiSixteenPlus.createInCallNotification(context, title, msg, iconID, contactIcon, contactName, intent);
|
||||
} else {
|
||||
notif = ApiElevenPlus.createInCallNotification(context, title, msg, iconID, contactIcon, contactName, intent);
|
||||
return ApiElevenPlus.createInCallNotification(context, title, msg, iconID, contactIcon, contactName, intent);
|
||||
}
|
||||
return notif;
|
||||
}
|
||||
|
||||
public static Notification createNotification(Context context, String title, String message, int icon, int iconLevel, Bitmap largeIcon, PendingIntent intent, boolean isOngoingEvent,int priority) {
|
||||
if (Version.sdkAboveOrEqual(Version.API21_LOLLIPOP_50)) {
|
||||
if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
|
||||
return ApiTwentySixPlus.createNotification(context, title, message, icon, iconLevel, largeIcon, intent, isOngoingEvent,priority);
|
||||
} else if (Version.sdkAboveOrEqual(Version.API21_LOLLIPOP_50)) {
|
||||
return ApiTwentyOnePlus.createNotification(context, title, message, icon, iconLevel, largeIcon, intent, isOngoingEvent,priority);
|
||||
} else if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) {
|
||||
return ApiSixteenPlus.createNotification(context, title, message, icon, iconLevel, largeIcon, intent, isOngoingEvent,priority);
|
||||
|
|
Loading…
Reference in a new issue