Added notification when missed call(s)

This commit is contained in:
Sylvain Berfini 2016-09-13 10:51:23 +02:00
parent 81639fe542
commit 1574778a0e
7 changed files with 86 additions and 6 deletions

View file

@ -170,6 +170,8 @@
<string name="incall_notif_video">Video capturing call ongoing</string>
<string name="notification_started">started</string>
<string name="unread_messages">%i unread messages</string>
<string name="missed_calls_notif_title">Missed call</string>
<string name="missed_calls_notif_body">%i missed calls</string>
<!-- Errors -->
<string name="skipable_error_service_not_ready">Warning: service is not ready</string>

View file

@ -1386,6 +1386,9 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
String sipUri = extras.getString("ChatContactSipUri");
doNotGoToCallActivity = true;
displayChat(sipUri);
} else if (extras != null && extras.getBoolean("GoToHistory", false)) {
doNotGoToCallActivity = true;
changeCurrentFragment(FragmentsAvailable.HISTORY_LIST, null);
} else if (extras != null && extras.getBoolean("Notification", false)) {
if (LinphoneManager.getLc().getCallsNb() > 0) {
LinphoneCall call = LinphoneManager.getLc().getCalls()[0];

View file

@ -89,6 +89,7 @@ public final class LinphoneService extends Service {
private final static int INCALL_NOTIF_ID=2;
private final static int MESSAGE_NOTIF_ID=3;
private final static int CUSTOM_NOTIF_ID=4;
private final static int MISSED_NOTIF_ID=5;
public static boolean isReady() {
return instance != null && instance.mTestDelayElapsed;
@ -114,7 +115,7 @@ public final class LinphoneService extends Service {
private Notification mMsgNotif;
private Notification mCustomNotif;
private int mMsgNotifCount;
private PendingIntent mNotifContentIntent;
private PendingIntent mNotifContentIntent, mMissedCallsNotifContentIntent;
private String mNotificationTitle;
private boolean mDisableRegistrationStatus;
private LinphoneCoreListenerBase mListener;
@ -181,6 +182,10 @@ public final class LinphoneService extends Service {
Intent notifIntent = new Intent(this, incomingReceivedActivity);
notifIntent.putExtra("Notification", true);
mNotifContentIntent = PendingIntent.getActivity(this, 0, notifIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent missedCallNotifIntent = new Intent(this, incomingReceivedActivity);
missedCallNotifIntent.putExtra("GoToHistory", true);
mMissedCallsNotifContentIntent = PendingIntent.getActivity(this, 0, missedCallNotifIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Bitmap bm = null;
try {
@ -215,11 +220,26 @@ public final class LinphoneService extends Service {
destroyOverlay();
}
// Enable the following to have missed call notifications
/*if (state == State.CallEnd && call.getCallLog().getStatus() == CallStatus.Missed) {
Notification notif = Compatibility.createSimpleNotification(instance, "Missed call", LinphoneManager.getLc().getMissedCallsCount() + " missed call", mNotifContentIntent);
notifyWrapper(CUSTOM_NOTIF_ID, notif);
}*/
if (state == State.CallEnd && call.getCallLog().getStatus() == CallStatus.Missed) {
int missedCallCount = LinphoneManager.getLcIfManagerNotDestroyedOrNull().getMissedCallsCount();
String body;
if (missedCallCount > 1) {
body = getString(R.string.missed_calls_notif_body).replace("%i", String.valueOf(missedCallCount));
} else {
LinphoneAddress address = call.getRemoteAddress();
LinphoneContact c = ContactsManager.getInstance().findContactFromAddress(address);
if (c != null) {
body = c.getFullName();
} else {
body = address.getDisplayName();
if (body == null) {
body = address.asStringUriOnly();
}
}
}
Notification notif = Compatibility.createMissedCallNotification(instance, getString(R.string.missed_calls_notif_title), body, mMissedCallsNotifContentIntent);
notifyWrapper(MISSED_NOTIF_ID, notif);
}
if (state == State.StreamsRunning) {
// Workaround bug current call seems to be updated after state changed to streams running

View file

@ -151,6 +151,20 @@ public class ApiElevenPlus {
return intent;
}
@SuppressWarnings("deprecation")
public static Notification createMissedCallNotification(Context context, String title, String text, PendingIntent intent) {
Notification notif = new Notification.Builder(context)
.setContentTitle(title)
.setContentText(text)
.setContentIntent(intent)
.setSmallIcon(R.drawable.call_status_missed)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
.setWhen(System.currentTimeMillis()).getNotification();
return notif;
}
@SuppressWarnings("deprecation")
public static Notification createSimpleNotification(Context context, String title, String text, PendingIntent intent) {
Notification notif = new Notification.Builder(context)

View file

@ -112,6 +112,20 @@ public class ApiSixteenPlus {
viewTreeObserver.removeOnGlobalLayoutListener(keyboardListener);
}
public static Notification createMissedCallNotification(Context context, String title, String text, PendingIntent intent) {
Notification notif = new Notification.Builder(context)
.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())
.build();
return notif;
}
public static Notification createSimpleNotification(Context context, String title, String text, PendingIntent intent) {
Notification notif = new Notification.Builder(context)
.setContentTitle(title)

View file

@ -112,6 +112,22 @@ public class ApiTwentyOnePlus {
viewTreeObserver.removeOnGlobalLayoutListener(keyboardListener);
}
public static Notification createMissedCallNotification(Context context, String title, String text, PendingIntent intent) {
Notification notif = new Notification.Builder(context)
.setContentTitle(title)
.setContentText(text)
.setSmallIcon(R.drawable.call_status_missed)
.setAutoCancel(true)
.setContentIntent(intent)
.setDefaults(Notification.DEFAULT_ALL)
.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)
.setContentTitle(title)

View file

@ -46,6 +46,17 @@ public class Compatibility {
}
return notif;
}
public static Notification createMissedCallNotification(Context context, String title, String text, PendingIntent intent) {
Notification notif = null;
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 notif;
}
public static Notification createMessageNotification(Context context, int msgCount, String msgSender, String msg, Bitmap contactIcon, PendingIntent intent) {
Notification notif = null;