@@ -34,12 +34,16 @@ public class IncomingCallNotificationService extends Service {
3434
3535 @ Override
3636 public int onStartCommand (Intent intent , int flags , int startId ) {
37+ if (BuildConfig .DEBUG ) {
38+ Log .d (TAG , "onStartCommand() intent: " + intent + ", flags: " + flags );
39+ }
3740 String action = intent .getAction ();
3841
3942 CallInvite callInvite = intent .getParcelableExtra (Constants .INCOMING_CALL_INVITE );
4043 int notificationId = intent .getIntExtra (Constants .INCOMING_CALL_NOTIFICATION_ID , 0 );
4144
4245 switch (action ) {
46+ // when a callInvite is received in the background
4347 case Constants .ACTION_INCOMING_CALL :
4448 handleIncomingCall (callInvite , notificationId );
4549 break ;
@@ -64,15 +68,16 @@ public IBinder onBind(Intent intent) {
6468 }
6569
6670 private Notification createNotification (CallInvite callInvite , int notificationId , int channelImportance ) {
67- Context ctx = getApplicationContext ();
71+ Context context = getApplicationContext ();
6872
69- Intent intent = new Intent (ctx , getMainActivityClass (ctx ));
70- intent .setAction (Constants .ACTION_OPEN_CALL_INVITE );
73+ Intent intent = new Intent (context , getMainActivityClass (context ));
74+ intent .setAction (Constants .ACTION_INCOMING_CALL );
7175 intent .putExtra (Constants .INCOMING_CALL_NOTIFICATION_ID , notificationId );
7276 intent .putExtra (Constants .INCOMING_CALL_INVITE , callInvite );
7377 intent .addFlags (Intent .FLAG_ACTIVITY_CLEAR_TOP );
78+
7479 PendingIntent pendingIntent =
75- PendingIntent .getActivity (ctx , notificationId , intent , PendingIntent .FLAG_UPDATE_CURRENT );
80+ PendingIntent .getActivity (context , notificationId , intent , PendingIntent .FLAG_UPDATE_CURRENT );
7681
7782 /*
7883 * Pass the notification id and call sid to use as an identifier to cancel the
@@ -117,24 +122,24 @@ private Notification buildNotification(String text, PendingIntent pendingIntent,
117122 final CallInvite callInvite ,
118123 int notificationId ,
119124 String channelId ) {
120- Context ctx = getApplicationContext ();
125+ Context context = getApplicationContext ();
121126
122- Intent rejectIntent = new Intent (ctx , IncomingCallNotificationService .class );
127+ Intent rejectIntent = new Intent (context , IncomingCallNotificationService .class );
123128 rejectIntent .setAction (Constants .ACTION_REJECT );
124129 rejectIntent .putExtra (Constants .INCOMING_CALL_INVITE , callInvite );
125130 rejectIntent .putExtra (Constants .INCOMING_CALL_NOTIFICATION_ID , notificationId );
126131 PendingIntent piRejectIntent = PendingIntent .getService (getApplicationContext (), 0 , rejectIntent , PendingIntent .FLAG_UPDATE_CURRENT );
127132 NotificationCompat .Action rejectAction = new NotificationCompat .Action .Builder (android .R .drawable .ic_menu_delete , getString (R .string .reject ), piRejectIntent ).build ();
128133
129- Intent acceptIntent = new Intent (ctx , IncomingCallNotificationService .class );
134+ Intent acceptIntent = new Intent (context , IncomingCallNotificationService .class );
130135 acceptIntent .setAction (Constants .ACTION_ACCEPT );
131136 acceptIntent .putExtra (Constants .INCOMING_CALL_INVITE , callInvite );
132137 acceptIntent .putExtra (Constants .INCOMING_CALL_NOTIFICATION_ID , notificationId );
133138 PendingIntent piAcceptIntent = PendingIntent .getService (getApplicationContext (), 0 , acceptIntent , PendingIntent .FLAG_UPDATE_CURRENT );
134139 NotificationCompat .Action answerAction = new NotificationCompat .Action .Builder (android .R .drawable .ic_menu_call , getString (R .string .accept ), piAcceptIntent ).build ();
135140
136141 NotificationCompat .Builder builder =
137- new NotificationCompat .Builder (ctx , channelId )
142+ new NotificationCompat .Builder (context , channelId )
138143 .setSmallIcon (R .drawable .ic_call_white_24dp )
139144 .setContentTitle (getString (R .string .call_incoming_title ))
140145 .setContentText (text )
@@ -149,8 +154,8 @@ private Notification buildNotification(String text, PendingIntent pendingIntent,
149154 .setContentIntent (pendingIntent );
150155
151156 // build notification large icon
152- Resources res = ctx .getResources ();
153- int largeIconResId = res .getIdentifier ("ic_launcher" , "mipmap" , ctx .getPackageName ());
157+ Resources res = context .getResources ();
158+ int largeIconResId = res .getIdentifier ("ic_launcher" , "mipmap" , context .getPackageName ());
154159 Bitmap largeIconBitmap = BitmapFactory .decodeResource (res , largeIconResId );
155160
156161 if (largeIconResId != 0 ) {
@@ -166,7 +171,6 @@ private String createChannel(int channelImportance) {
166171 if (channelImportance == NotificationManager .IMPORTANCE_LOW ) {
167172 channelId = Constants .VOICE_CHANNEL_LOW_IMPORTANCE ;
168173 }
169- Log .d (TAG , "channel importance: %d" + channelImportance );
170174 NotificationChannel callInviteChannel = new NotificationChannel (channelId ,
171175 "Incoming calls" , channelImportance );
172176 callInviteChannel .setLightColor (Color .GREEN );
@@ -226,7 +230,7 @@ private void setCallInProgressNotification(CallInvite callInvite, int notificati
226230 int importance = NotificationManager .IMPORTANCE_LOW ;
227231 if (!isAppVisible ()) {
228232 if (BuildConfig .DEBUG ) {
229- Log .i (TAG , "setCallInProgressNotification - app is NOT visible." );
233+ Log .i (TAG , "app is NOT visible." );
230234 }
231235 importance = NotificationManager .IMPORTANCE_HIGH ;
232236 }
@@ -237,6 +241,9 @@ private void setCallInProgressNotification(CallInvite callInvite, int notificati
237241 * Send the CallInvite to the Activity. Start the activity if it is not running already.
238242 */
239243 private void sendCallInviteToActivity (CallInvite callInvite , int notificationId ) {
244+ // TODO in case the app is killed there is not enough time for the incoming call event to be sent to JS
245+ // therefore leaving the heads up notification present is the only way to allow the call to be answered
246+ // endForeground();
240247 if (BuildConfig .DEBUG ) {
241248 Log .d (TAG , "sendCallInviteToActivity()" );
242249 }
0 commit comments