Added notification when missed call(s)
This commit is contained in:
parent
81639fe542
commit
1574778a0e
7 changed files with 86 additions and 6 deletions
|
@ -170,6 +170,8 @@
|
||||||
<string name="incall_notif_video">Video capturing call ongoing</string>
|
<string name="incall_notif_video">Video capturing call ongoing</string>
|
||||||
<string name="notification_started">started</string>
|
<string name="notification_started">started</string>
|
||||||
<string name="unread_messages">%i unread messages</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 -->
|
<!-- Errors -->
|
||||||
<string name="skipable_error_service_not_ready">Warning: service is not ready</string>
|
<string name="skipable_error_service_not_ready">Warning: service is not ready</string>
|
||||||
|
|
|
@ -1386,6 +1386,9 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
||||||
String sipUri = extras.getString("ChatContactSipUri");
|
String sipUri = extras.getString("ChatContactSipUri");
|
||||||
doNotGoToCallActivity = true;
|
doNotGoToCallActivity = true;
|
||||||
displayChat(sipUri);
|
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)) {
|
} else if (extras != null && extras.getBoolean("Notification", false)) {
|
||||||
if (LinphoneManager.getLc().getCallsNb() > 0) {
|
if (LinphoneManager.getLc().getCallsNb() > 0) {
|
||||||
LinphoneCall call = LinphoneManager.getLc().getCalls()[0];
|
LinphoneCall call = LinphoneManager.getLc().getCalls()[0];
|
||||||
|
|
|
@ -89,6 +89,7 @@ public final class LinphoneService extends Service {
|
||||||
private final static int INCALL_NOTIF_ID=2;
|
private final static int INCALL_NOTIF_ID=2;
|
||||||
private final static int MESSAGE_NOTIF_ID=3;
|
private final static int MESSAGE_NOTIF_ID=3;
|
||||||
private final static int CUSTOM_NOTIF_ID=4;
|
private final static int CUSTOM_NOTIF_ID=4;
|
||||||
|
private final static int MISSED_NOTIF_ID=5;
|
||||||
|
|
||||||
public static boolean isReady() {
|
public static boolean isReady() {
|
||||||
return instance != null && instance.mTestDelayElapsed;
|
return instance != null && instance.mTestDelayElapsed;
|
||||||
|
@ -114,7 +115,7 @@ public final class LinphoneService extends Service {
|
||||||
private Notification mMsgNotif;
|
private Notification mMsgNotif;
|
||||||
private Notification mCustomNotif;
|
private Notification mCustomNotif;
|
||||||
private int mMsgNotifCount;
|
private int mMsgNotifCount;
|
||||||
private PendingIntent mNotifContentIntent;
|
private PendingIntent mNotifContentIntent, mMissedCallsNotifContentIntent;
|
||||||
private String mNotificationTitle;
|
private String mNotificationTitle;
|
||||||
private boolean mDisableRegistrationStatus;
|
private boolean mDisableRegistrationStatus;
|
||||||
private LinphoneCoreListenerBase mListener;
|
private LinphoneCoreListenerBase mListener;
|
||||||
|
@ -182,6 +183,10 @@ public final class LinphoneService extends Service {
|
||||||
notifIntent.putExtra("Notification", true);
|
notifIntent.putExtra("Notification", true);
|
||||||
mNotifContentIntent = PendingIntent.getActivity(this, 0, notifIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
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;
|
Bitmap bm = null;
|
||||||
try {
|
try {
|
||||||
bm = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
|
bm = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
|
||||||
|
@ -215,11 +220,26 @@ public final class LinphoneService extends Service {
|
||||||
destroyOverlay();
|
destroyOverlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable the following to have missed call notifications
|
if (state == State.CallEnd && call.getCallLog().getStatus() == CallStatus.Missed) {
|
||||||
/*if (state == State.CallEnd && call.getCallLog().getStatus() == CallStatus.Missed) {
|
int missedCallCount = LinphoneManager.getLcIfManagerNotDestroyedOrNull().getMissedCallsCount();
|
||||||
Notification notif = Compatibility.createSimpleNotification(instance, "Missed call", LinphoneManager.getLc().getMissedCallsCount() + " missed call", mNotifContentIntent);
|
String body;
|
||||||
notifyWrapper(CUSTOM_NOTIF_ID, notif);
|
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) {
|
if (state == State.StreamsRunning) {
|
||||||
// Workaround bug current call seems to be updated after state changed to streams running
|
// Workaround bug current call seems to be updated after state changed to streams running
|
||||||
|
|
|
@ -151,6 +151,20 @@ public class ApiElevenPlus {
|
||||||
return intent;
|
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")
|
@SuppressWarnings("deprecation")
|
||||||
public static Notification createSimpleNotification(Context context, String title, String text, PendingIntent intent) {
|
public static Notification createSimpleNotification(Context context, String title, String text, PendingIntent intent) {
|
||||||
Notification notif = new Notification.Builder(context)
|
Notification notif = new Notification.Builder(context)
|
||||||
|
|
|
@ -112,6 +112,20 @@ public class ApiSixteenPlus {
|
||||||
viewTreeObserver.removeOnGlobalLayoutListener(keyboardListener);
|
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) {
|
public static Notification createSimpleNotification(Context context, String title, String text, PendingIntent intent) {
|
||||||
Notification notif = new Notification.Builder(context)
|
Notification notif = new Notification.Builder(context)
|
||||||
.setContentTitle(title)
|
.setContentTitle(title)
|
||||||
|
|
|
@ -112,6 +112,22 @@ public class ApiTwentyOnePlus {
|
||||||
viewTreeObserver.removeOnGlobalLayoutListener(keyboardListener);
|
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) {
|
public static Notification createSimpleNotification(Context context, String title, String text, PendingIntent intent) {
|
||||||
Notification notif = new Notification.Builder(context)
|
Notification notif = new Notification.Builder(context)
|
||||||
.setContentTitle(title)
|
.setContentTitle(title)
|
||||||
|
|
|
@ -46,6 +46,17 @@ public class Compatibility {
|
||||||
}
|
}
|
||||||
return notif;
|
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) {
|
public static Notification createMessageNotification(Context context, int msgCount, String msgSender, String msg, Bitmap contactIcon, PendingIntent intent) {
|
||||||
Notification notif = null;
|
Notification notif = null;
|
||||||
|
|
Loading…
Reference in a new issue