Ability to set notification priority (API>16), also when used as a Library

This commit is contained in:
Christophe Deschamps 2015-07-02 01:32:09 +02:00
parent 991de56c8c
commit d3d54fd1c0
4 changed files with 14 additions and 10 deletions

View file

@ -116,6 +116,7 @@ public final class LinphoneService extends Service {
private String mNotificationTitle; private String mNotificationTitle;
private boolean mDisableRegistrationStatus; private boolean mDisableRegistrationStatus;
private LinphoneCoreListenerBase mListener; private LinphoneCoreListenerBase mListener;
public static int notifcationsPriority = (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41) ? Notification.PRIORITY_DEFAULT : 0);
public int getMessageNotifCount() { public int getMessageNotifCount() {
return mMsgNotifCount; return mMsgNotifCount;
@ -153,7 +154,7 @@ public final class LinphoneService extends Service {
bm = BitmapFactory.decodeResource(getResources(), R.drawable.logo_linphone_57x57); bm = BitmapFactory.decodeResource(getResources(), R.drawable.logo_linphone_57x57);
} catch (Exception e) { } catch (Exception e) {
} }
mNotif = Compatibility.createNotification(this, mNotificationTitle, "", R.drawable.status_level, IC_LEVEL_OFFLINE, bm, mNotifContentIntent, true); mNotif = Compatibility.createNotification(this, mNotificationTitle, "", R.drawable.status_level, IC_LEVEL_OFFLINE, bm, mNotifContentIntent, true,notifcationsPriority);
LinphoneManager.createAndStart(LinphoneService.this); LinphoneManager.createAndStart(LinphoneService.this);
@ -271,6 +272,7 @@ public final class LinphoneService extends Service {
} }
}; };
private enum IncallIconState {INCALL, PAUSE, VIDEO, IDLE} private enum IncallIconState {INCALL, PAUSE, VIDEO, IDLE}
private IncallIconState mCurrentIncallIconState = IncallIconState.IDLE; private IncallIconState mCurrentIncallIconState = IncallIconState.IDLE;
@ -357,7 +359,7 @@ public final class LinphoneService extends Service {
bm = BitmapFactory.decodeResource(getResources(), R.drawable.logo_linphone_57x57); bm = BitmapFactory.decodeResource(getResources(), R.drawable.logo_linphone_57x57);
} catch (Exception e) { } catch (Exception e) {
} }
mCustomNotif = Compatibility.createNotification(this, title, message, iconResourceID, 0, bm, notifContentIntent, isOngoingEvent); mCustomNotif = Compatibility.createNotification(this, title, message, iconResourceID, 0, bm, notifContentIntent, isOngoingEvent,notifcationsPriority);
mCustomNotif.defaults |= Notification.DEFAULT_VIBRATE; mCustomNotif.defaults |= Notification.DEFAULT_VIBRATE;
mCustomNotif.defaults |= Notification.DEFAULT_SOUND; mCustomNotif.defaults |= Notification.DEFAULT_SOUND;
@ -529,7 +531,7 @@ public final class LinphoneService extends Service {
bm = BitmapFactory.decodeResource(getResources(), R.drawable.logo_linphone_57x57); bm = BitmapFactory.decodeResource(getResources(), R.drawable.logo_linphone_57x57);
} catch (Exception e) { } catch (Exception e) {
} }
mNotif = Compatibility.createNotification(this, mNotificationTitle, text, R.drawable.status_level, level, bm, mNotifContentIntent, true); mNotif = Compatibility.createNotification(this, mNotificationTitle, text, R.drawable.status_level, level, bm, mNotifContentIntent, true,notifcationsPriority);
notifyWrapper(NOTIF_ID, mNotif); notifyWrapper(NOTIF_ID, mNotif);
} }

View file

@ -76,7 +76,7 @@ public class ApiSixteenPlus {
return notif; return notif;
} }
public static Notification createNotification(Context context, String title, String message, int icon, int level, Bitmap largeIcon, PendingIntent intent, boolean isOngoingEvent) { public static Notification createNotification(Context context, String title, String message, int icon, int level, Bitmap largeIcon, PendingIntent intent, boolean isOngoingEvent,int priority) {
Notification notif; Notification notif;
if (largeIcon != null) { if (largeIcon != null) {
@ -87,6 +87,7 @@ public class ApiSixteenPlus {
.setLargeIcon(largeIcon) .setLargeIcon(largeIcon)
.setContentIntent(intent) .setContentIntent(intent)
.setWhen(System.currentTimeMillis()) .setWhen(System.currentTimeMillis())
.setPriority(priority)
.build(); .build();
} else { } else {
notif = new Notification.Builder(context) notif = new Notification.Builder(context)
@ -95,6 +96,7 @@ public class ApiSixteenPlus {
.setSmallIcon(icon, level) .setSmallIcon(icon, level)
.setContentIntent(intent) .setContentIntent(intent)
.setWhen(System.currentTimeMillis()) .setWhen(System.currentTimeMillis())
.setPriority(priority)
.build(); .build();
} }
if (isOngoingEvent) { if (isOngoingEvent) {

View file

@ -78,7 +78,7 @@ public class ApiTwentyOnePlus {
return notif; return notif;
} }
public static Notification createNotification(Context context, String title, String message, int icon, int level, Bitmap largeIcon, PendingIntent intent, boolean isOngoingEvent) { public static Notification createNotification(Context context, String title, String message, int icon, int level, Bitmap largeIcon, PendingIntent intent, boolean isOngoingEvent,int priority) {
Notification notif; Notification notif;
if (largeIcon != null) { if (largeIcon != null) {
@ -90,7 +90,7 @@ public class ApiTwentyOnePlus {
.setContentIntent(intent) .setContentIntent(intent)
.setCategory(Notification.CATEGORY_SERVICE) .setCategory(Notification.CATEGORY_SERVICE)
.setVisibility(Notification.VISIBILITY_SECRET) .setVisibility(Notification.VISIBILITY_SECRET)
.setPriority(Notification.PRIORITY_DEFAULT) .setPriority(priority)
.build(); .build();
} else { } else {
notif = new NotificationCompat.Builder(context) notif = new NotificationCompat.Builder(context)
@ -100,7 +100,7 @@ public class ApiTwentyOnePlus {
.setContentIntent(intent) .setContentIntent(intent)
.setCategory(Notification.CATEGORY_SERVICE) .setCategory(Notification.CATEGORY_SERVICE)
.setVisibility(Notification.VISIBILITY_SECRET) .setVisibility(Notification.VISIBILITY_SECRET)
.setPriority(Notification.PRIORITY_DEFAULT) .setPriority(priority)
.build(); .build();
} }

View file

@ -204,11 +204,11 @@ public class Compatibility {
return notif; return notif;
} }
public static Notification createNotification(Context context, String title, String message, int icon, int iconLevel, Bitmap largeIcon, PendingIntent intent, boolean isOngoingEvent) { 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.API21_LOLLIPOP_50)) {
return ApiTwentyOnePlus.createNotification(context, title, message, icon, iconLevel, largeIcon, intent, isOngoingEvent); return ApiTwentyOnePlus.createNotification(context, title, message, icon, iconLevel, largeIcon, intent, isOngoingEvent,priority);
} else if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) { } else if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) {
return ApiSixteenPlus.createNotification(context, title, message, icon, iconLevel, largeIcon, intent, isOngoingEvent); return ApiSixteenPlus.createNotification(context, title, message, icon, iconLevel, largeIcon, intent, isOngoingEvent,priority);
} else if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) { } else if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) {
return ApiElevenPlus.createNotification(context, title, message, icon, iconLevel, largeIcon, intent, isOngoingEvent); return ApiElevenPlus.createNotification(context, title, message, icon, iconLevel, largeIcon, intent, isOngoingEvent);
} else { } else {