Improved API to add custom notification
This commit is contained in:
parent
9e591188f1
commit
6dc5194656
5 changed files with 25 additions and 15 deletions
|
@ -151,7 +151,7 @@ public final class LinphoneService extends Service implements LinphoneServiceLis
|
|||
bm = BitmapFactory.decodeResource(getResources(), R.drawable.logo_linphone_57x57);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
mNotif = Compatibility.createNotification(this, mNotificationTitle, "", R.drawable.status_level, IC_LEVEL_OFFLINE, bm, mNotifContentIntent);
|
||||
mNotif = Compatibility.createNotification(this, mNotificationTitle, "", R.drawable.status_level, IC_LEVEL_OFFLINE, bm, mNotifContentIntent, true);
|
||||
|
||||
LinphoneManager.createAndStart(this, this);
|
||||
mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
|
||||
|
@ -275,7 +275,12 @@ public final class LinphoneService extends Service implements LinphoneServiceLis
|
|||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void addNotification(Intent onClickIntent, int iconResourceID, String title, String message) {
|
||||
addCustomNotification(onClickIntent, iconResourceID, title, message, true);
|
||||
}
|
||||
|
||||
public void addCustomNotification(Intent onClickIntent, int iconResourceID, String title, String message, boolean isOngoingEvent) {
|
||||
PendingIntent notifContentIntent = PendingIntent.getActivity(this, 0, onClickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
Bitmap bm = null;
|
||||
|
@ -283,7 +288,7 @@ public final class LinphoneService extends Service implements LinphoneServiceLis
|
|||
bm = BitmapFactory.decodeResource(getResources(), R.drawable.logo_linphone_57x57);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
mCustomNotif = Compatibility.createNotification(this, title, message, iconResourceID, 0, bm, notifContentIntent);
|
||||
mCustomNotif = Compatibility.createNotification(this, title, message, iconResourceID, 0, bm, notifContentIntent, isOngoingEvent);
|
||||
|
||||
mCustomNotif.defaults |= Notification.DEFAULT_VIBRATE;
|
||||
mCustomNotif.defaults |= Notification.DEFAULT_SOUND;
|
||||
|
@ -448,7 +453,7 @@ public final class LinphoneService extends Service implements LinphoneServiceLis
|
|||
bm = BitmapFactory.decodeResource(getResources(), R.drawable.logo_linphone_57x57);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
mNotif = Compatibility.createNotification(this, mNotificationTitle, text, R.drawable.status_level, level, bm, mNotifContentIntent);
|
||||
mNotif = Compatibility.createNotification(this, mNotificationTitle, text, R.drawable.status_level, level, bm, mNotifContentIntent, true);
|
||||
notifyWrapper(NOTIF_ID, mNotif);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@ import android.net.Uri;
|
|||
import android.provider.ContactsContract;
|
||||
import android.provider.ContactsContract.CommonDataKinds.Im;
|
||||
import android.provider.ContactsContract.Contacts;
|
||||
import android.provider.ContactsContract.CommonDataKinds.SipAddress;
|
||||
import android.provider.ContactsContract.Intents.Insert;
|
||||
|
||||
/*
|
||||
|
@ -92,7 +91,7 @@ public class ApiElevenPlus {
|
|||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Notification createNotification(Context context, String title, String message, int icon, int level, Bitmap largeIcon, PendingIntent intent) {
|
||||
public static Notification createNotification(Context context, String title, String message, int icon, int level, Bitmap largeIcon, PendingIntent intent, boolean isOngoingEvent) {
|
||||
Notification notif;
|
||||
|
||||
if (largeIcon != null) {
|
||||
|
@ -113,7 +112,9 @@ public class ApiElevenPlus {
|
|||
.setWhen(System.currentTimeMillis())
|
||||
.getNotification();
|
||||
}
|
||||
notif.flags |= Notification.FLAG_ONGOING_EVENT;
|
||||
if (isOngoingEvent) {
|
||||
notif.flags |= Notification.FLAG_ONGOING_EVENT;
|
||||
}
|
||||
|
||||
return notif;
|
||||
}
|
||||
|
|
|
@ -367,12 +367,14 @@ public class ApiFivePlus {
|
|||
//manager.setMode(AudioManager.MODE_IN_CALL);
|
||||
}
|
||||
|
||||
public static Notification createNotification(Context context, String title, String message, int icon, int level, PendingIntent intent) {
|
||||
public static Notification createNotification(Context context, String title, String message, int icon, int level, PendingIntent intent, boolean isOngoingEvent) {
|
||||
Notification notif = new Notification();
|
||||
notif.icon = icon;
|
||||
notif.iconLevel = level;
|
||||
notif.when = System.currentTimeMillis();
|
||||
notif.flags |= Notification.FLAG_ONGOING_EVENT;
|
||||
if (isOngoingEvent) {
|
||||
notif.flags |= Notification.FLAG_ONGOING_EVENT;
|
||||
}
|
||||
notif.setLatestEventInfo(context, title, message, intent);
|
||||
|
||||
return notif;
|
||||
|
|
|
@ -71,12 +71,12 @@ public class ApiSixteenPlus {
|
|||
.setContentIntent(intent)
|
||||
.setWhen(System.currentTimeMillis())
|
||||
.setLargeIcon(contactIcon).build();
|
||||
|
||||
notif.flags |= Notification.FLAG_ONGOING_EVENT;
|
||||
|
||||
return notif;
|
||||
}
|
||||
|
||||
public static Notification createNotification(Context context, String title, String message, int icon, int level, Bitmap largeIcon, PendingIntent intent) {
|
||||
public static Notification createNotification(Context context, String title, String message, int icon, int level, Bitmap largeIcon, PendingIntent intent, boolean isOngoingEvent) {
|
||||
Notification notif;
|
||||
|
||||
if (largeIcon != null) {
|
||||
|
@ -97,7 +97,9 @@ public class ApiSixteenPlus {
|
|||
.setWhen(System.currentTimeMillis())
|
||||
.build();
|
||||
}
|
||||
notif.flags |= Notification.FLAG_ONGOING_EVENT;
|
||||
if (isOngoingEvent) {
|
||||
notif.flags |= Notification.FLAG_ONGOING_EVENT;
|
||||
}
|
||||
|
||||
return notif;
|
||||
}
|
||||
|
|
|
@ -173,13 +173,13 @@ public class Compatibility {
|
|||
return notif;
|
||||
}
|
||||
|
||||
public static Notification createNotification(Context context, String title, String message, int icon, int iconLevel, Bitmap largeIcon, PendingIntent intent) {
|
||||
public static Notification createNotification(Context context, String title, String message, int icon, int iconLevel, Bitmap largeIcon, PendingIntent intent, boolean isOngoingEvent) {
|
||||
if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) {
|
||||
return ApiSixteenPlus.createNotification(context, title, message, icon, iconLevel, largeIcon, intent);
|
||||
return ApiSixteenPlus.createNotification(context, title, message, icon, iconLevel, largeIcon, intent, isOngoingEvent);
|
||||
} else if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) {
|
||||
return ApiElevenPlus.createNotification(context, title, message, icon, iconLevel, largeIcon, intent);
|
||||
return ApiElevenPlus.createNotification(context, title, message, icon, iconLevel, largeIcon, intent, isOngoingEvent);
|
||||
} else {
|
||||
return ApiFivePlus.createNotification(context, title, message, icon, iconLevel, intent);
|
||||
return ApiFivePlus.createNotification(context, title, message, icon, iconLevel, intent, isOngoingEvent);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue