44import android .app .NotificationManager ;
55import android .app .PendingIntent ;
66import android .app .Service ;
7+ import android .app .TaskStackBuilder ;
78import android .content .Context ;
89import android .content .Intent ;
910import android .os .Build ;
1516
1617import com .cometchat .pro .core .CometChat ;
1718import com .cometchat .pro .uikit .R ;
19+ import com .cometchat .pro .uikit .ui_components .calls .call_manager .CometChatStartCallActivity ;
1820import com .cometchat .pro .uikit .ui_components .cometchat_ui .CometChatUI ;
1921import com .cometchat .pro .uikit .ui_resources .constants .UIKitConstants ;
2022
@@ -27,13 +29,14 @@ public class OngoingCallService extends Service {
2729 private int counter = 0 ;
2830
2931 NotificationManager notificationManager ;
32+
3033 @ Override
3134 public void onCreate () {
3235 super .onCreate ();
3336 if (Build .VERSION .SDK_INT > Build .VERSION_CODES .O )
3437 startMyOwnForeground ();
3538 else
36- this .startForeground (1 ,new Notification ());
39+ this .startForeground (1 , new Notification ());
3740 }
3841
3942 @ Nullable
@@ -46,12 +49,35 @@ private void startMyOwnForeground() {
4649 notificationManager = (NotificationManager ) getSystemService (Context .NOTIFICATION_SERVICE );
4750 notificationManager .cancel (2 );
4851 PendingIntent pendingIntent = null ;
49- if (CometChat .getActiveCall ()!=null ) {
50- pendingIntent = PendingIntent .getBroadcast (getApplicationContext (),REQUEST_CODE ,
51- getCallIntent ("Ongoing" ),
52- PendingIntent .FLAG_IMMUTABLE | PendingIntent .FLAG_UPDATE_CURRENT );
52+ if (CometChat .getActiveCall () != null ) {
53+ if (Build .VERSION .SDK_INT >= 31 ) {
54+ Intent joinOngoingIntent =
55+ new Intent (getApplicationContext (), CometChatStartCallActivity .class );
56+ joinOngoingIntent .putExtra (
57+ UIKitConstants .IntentStrings .SESSION_ID ,
58+ CometChat .getActiveCall ().getSessionId ()
59+ );
60+ joinOngoingIntent .putExtra (
61+ UIKitConstants .IntentStrings .TYPE ,
62+ CometChat .getActiveCall ().getType ()
63+ );
64+ joinOngoingIntent .setFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
65+
66+ TaskStackBuilder stackBuilder = TaskStackBuilder .create (this );
67+ stackBuilder .addNextIntent (joinOngoingIntent );
68+ pendingIntent = stackBuilder .getPendingIntent (
69+ REQUEST_CODE ,
70+ PendingIntent .FLAG_UPDATE_CURRENT | PendingIntent .FLAG_IMMUTABLE
71+ );
72+
73+ } else {
74+ pendingIntent = PendingIntent .getBroadcast (getApplicationContext (), REQUEST_CODE ,
75+ getCallIntent ("Ongoing" ),
76+ PendingIntent .FLAG_IMMUTABLE | PendingIntent .FLAG_UPDATE_CURRENT );
77+ }
5378 }
54- NotificationCompat .Builder notificationBuilder = new NotificationCompat .Builder (this ,"2" );
79+ Log .e ("" , "startMyOwnForeground: " +pendingIntent );
80+ NotificationCompat .Builder notificationBuilder = new NotificationCompat .Builder (this , "2" );
5581 Notification notification = notificationBuilder .setOngoing (true )
5682 .setSmallIcon (R .drawable .cc )
5783 .setColor (getResources ().getColor (R .color .colorPrimary ))
@@ -60,13 +86,13 @@ private void startMyOwnForeground() {
6086 .setContentIntent (pendingIntent )
6187 .setCategory (Notification .CATEGORY_CALL )
6288 .build ();
63- startForeground (1 ,notification );
89+ startForeground (1 , notification );
6490 }
6591
6692 private Intent getCallIntent (String title ) {
6793 Intent callIntent ;
68- if (CometChat .getActiveCall ()!= null ) {
69- callIntent = new Intent (getApplicationContext (),OngoingCallBroadcast .class );
94+ if (CometChat .getActiveCall () != null ) {
95+ callIntent = new Intent (getApplicationContext (), OngoingCallBroadcast .class );
7096 callIntent .putExtra (UIKitConstants .IntentStrings .SESSION_ID , CometChat .getActiveCall ().getSessionId ());
7197 callIntent .putExtra (UIKitConstants .IntentStrings .TYPE , CometChat .getActiveCall ().getType ());
7298 callIntent .addFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
@@ -101,21 +127,22 @@ public boolean stopService(Intent name) {
101127
102128 private Timer timer ;
103129 private TimerTask timerTask ;
130+
104131 public void startTimer () {
105132 timer = new Timer ();
106133 timerTask = new TimerTask () {
107134 @ Override
108135 public void run () {
109- Log .d ("AppInBackground: " ,"" + counter ++ );
136+ Log .d ("AppInBackground: " , "" + counter ++);
110137 }
111138 };
112139 timer .schedule (timerTask , 1000 , 1000 );
113140 }
114141
115142 public void stopTimer () {
116- if (timer != null ) {
143+ if (timer != null ) {
117144 timer .cancel ();
118145 timer = null ;
119146 }
120147 }
121- }
148+ }
0 commit comments