6
6
import android .app .NotificationManager ;
7
7
import android .app .PendingIntent ;
8
8
import android .app .Service ;
9
- import android .content .BroadcastReceiver ;
10
9
import android .content .Context ;
11
10
import android .content .Intent ;
12
- import android .content .IntentFilter ;
13
11
import android .content .res .Resources ;
14
12
import android .graphics .Color ;
15
13
import android .media .AudioAttributes ;
16
- import android .media .AudioManager ;
17
- import android .media .Ringtone ;
18
14
import android .media .RingtoneManager ;
19
15
import android .os .Build ;
20
16
import android .os .Bundle ;
21
17
import android .os .Handler ;
22
18
import android .os .IBinder ;
23
- import android .os .VibrationEffect ;
24
- import android .os .Vibrator ;
25
19
import android .util .Log ;
26
20
21
+
27
22
import androidx .annotation .Nullable ;
28
23
import androidx .core .app .NotificationCompat ;
29
24
import androidx .core .content .ContextCompat ;
@@ -37,15 +32,15 @@ public class IncomingCallService extends Service {
37
32
public static Handler callhandle ;
38
33
private String uuid = "" ;
39
34
private Integer timeoutNumber =0 ;
35
+ private boolean isRegistered = false ;
36
+ // you can perform a click only once time
37
+ private Bundle bundleData ;
40
38
private static final String TAG = "FullscreenSevice" ;
41
39
public int onStartCommand (Intent intent , int flags , int startId ) {
42
40
String action = intent .getAction ();
43
41
if (action != null ) {
44
42
if (action .equals (Constants .ACTION_SHOW_INCOMING_CALL )) {
45
- IntentFilter filter = new IntentFilter ();
46
- filter .addAction (Constants .ACTION_PRESS_ANSWER_CALL );
47
- filter .addAction (Constants .ACTION_PRESS_DECLINE_CALL );
48
- getApplicationContext ().registerReceiver (mReceiver , filter );
43
+ NotificationReceiverHandler .updateCanClick (true );
49
44
Bundle bundle = intent .getExtras ();
50
45
uuid = bundle .getString ("uuid" );
51
46
if (bundle .containsKey ("timeout" )){
@@ -78,24 +73,25 @@ public void onTaskRemoved(Intent rootIntent) {
78
73
stopSelf ();
79
74
}
80
75
81
- private PendingIntent onButtonNotificationClick (int id , String action ) {
82
- Intent buttonIntent = new Intent ();
83
- buttonIntent .setAction (action );
84
- return PendingIntent .getBroadcast (this ,id , buttonIntent , PendingIntent .FLAG_IMMUTABLE );
76
+
77
+ private PendingIntent onButtonNotificationClick (int id , String action ,String eventName ) {
78
+ Intent emptyScreenIntent = new Intent (this , NotificationReceiverActivity .class );
79
+ emptyScreenIntent .setAction (action );
80
+ emptyScreenIntent .putExtras (bundleData );
81
+ emptyScreenIntent .putExtra ("eventName" ,eventName );
82
+ return PendingIntent .getActivity (this , 0 , emptyScreenIntent , PendingIntent .FLAG_UPDATE_CURRENT | PendingIntent .FLAG_IMMUTABLE );
85
83
}
86
84
87
85
private Notification buildNotification (Context context , Intent intent ) {
88
- Intent fullScreenIntent = new Intent (context , IncomingCallActivity .class );
86
+
87
+ Intent emptyScreenIntent = new Intent (context , NotificationReceiverActivity .class );
89
88
Bundle bundle = intent .getExtras ();
90
- fullScreenIntent .putExtra ("uuid" , uuid );
91
- fullScreenIntent .putExtra ("name" , bundle .getString ("name" ));
92
- fullScreenIntent .putExtra ("avatar" , bundle .getString ("avatar" ));
93
- fullScreenIntent .putExtra ("info" , bundle .getString ("info" ));
94
- fullScreenIntent .putExtra ("declineText" , bundle .getString ("declineText" ));
95
- fullScreenIntent .putExtra ("answerText" , bundle .getString ("answerText" ));
89
+ bundleData =bundle ;
90
+ emptyScreenIntent .putExtras (bundle );
91
+ emptyScreenIntent .setFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
92
+ emptyScreenIntent .setAction (Constants .onPressNotification );
96
93
String channelId =bundle .getString ("channelId" );
97
- fullScreenIntent .setFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
98
- PendingIntent fullScreenPendingIntent = PendingIntent .getActivity (context , 0 , fullScreenIntent , PendingIntent .FLAG_UPDATE_CURRENT | PendingIntent .FLAG_IMMUTABLE );
94
+ PendingIntent emptyPendingIntent = PendingIntent .getActivity (context , 0 , emptyScreenIntent , PendingIntent .FLAG_UPDATE_CURRENT | PendingIntent .FLAG_IMMUTABLE );
99
95
NotificationManager notificationManager = (NotificationManager ) getSystemService (NOTIFICATION_SERVICE );
100
96
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
101
97
NotificationChannel notificationChannel =new NotificationChannel (channelId , bundle .getString ("channelName" ), NotificationManager .IMPORTANCE_HIGH );
@@ -117,16 +113,16 @@ private Notification buildNotification(Context context, Intent intent) {
117
113
.setContentText (bundle .getString ("info" ))
118
114
.setPriority (NotificationCompat .PRIORITY_MAX )
119
115
.setCategory (NotificationCompat .CATEGORY_CALL )
120
- .setContentIntent (fullScreenPendingIntent )
116
+ .setContentIntent (emptyPendingIntent )
121
117
.addAction (
122
118
0 ,
123
119
bundle .getString ("declineText" ),
124
- onButtonNotificationClick (0 ,Constants .ACTION_PRESS_DECLINE_CALL )
120
+ onButtonNotificationClick (0 ,Constants .ACTION_PRESS_DECLINE_CALL , Constants . RNNotificationEndCallAction )
125
121
)
126
122
.addAction (
127
123
0 ,
128
124
bundle .getString ("answerText" ),
129
- onButtonNotificationClick (1 ,Constants .ACTION_PRESS_ANSWER_CALL )
125
+ onButtonNotificationClick (1 ,Constants .ACTION_PRESS_ANSWER_CALL , Constants . RNNotificationAnswerAction )
130
126
)
131
127
.setAutoCancel (true )
132
128
.setOngoing (true )
@@ -138,7 +134,7 @@ private Notification buildNotification(Context context, Intent intent) {
138
134
// interacts with the notification. Also, if your app targets Android 10
139
135
// or higher, you need to request the USE_FULL_SCREEN_INTENT permission in
140
136
// order for the platform to invoke this notification.
141
- .setFullScreenIntent (fullScreenPendingIntent , true );
137
+ .setFullScreenIntent (emptyPendingIntent , true );
142
138
if (bundle .getString ("notificationColor" )!=null ){
143
139
notificationBuilder .setColor (getColorForResourceName (context ,bundle .getString ("notificationColor" )));
144
140
}
@@ -164,6 +160,7 @@ public void onDestroy() {
164
160
cancelTimer ();
165
161
stopForeground (true );
166
162
}
163
+
167
164
public void setTimeOutEndCall (String uuid ) {
168
165
callhandle =new Handler ();
169
166
handleTimeout =new Runnable () {
@@ -186,39 +183,7 @@ public void cancelTimer(){
186
183
callhandle .removeCallbacks (handleTimeout );
187
184
}
188
185
}
189
- private BroadcastReceiver mReceiver = new BroadcastReceiver () {
190
- @ Override
191
- public void onReceive (Context context , Intent intent ) {
192
- String action = intent .getAction ();
193
- if (action != null ) {
194
- if (action .equals (Constants .ACTION_PRESS_ANSWER_CALL )) {
195
- cancelTimer ();
196
186
197
- if (Build .VERSION .SDK_INT < Build .VERSION_CODES .S ) {
198
- Intent it = new Intent (Intent .ACTION_CLOSE_SYSTEM_DIALOGS );
199
- context .sendBroadcast (it );
200
- }
201
- if (IncomingCallActivity .active ) {
202
- IncomingCallActivity .getInstance ().destroyActivity (false );
203
- }
204
- WritableMap params = Arguments .createMap ();
205
- params .putString ("callUUID" , uuid );
206
- FullScreenNotificationIncomingCallModule .sendEventToJs (Constants .RNNotificationAnswerAction ,params );
207
- stopForeground (true );
208
- }else if (action .equals (Constants .ACTION_PRESS_DECLINE_CALL )){
209
- cancelTimer ();
210
- if (IncomingCallActivity .active ) {
211
- IncomingCallActivity .getInstance ().destroyActivity (false );
212
- }
213
- WritableMap params = Arguments .createMap ();
214
- params .putString ("callUUID" , uuid );
215
- params .putString ("endAction" , Constants .ACTION_REJECTED_CALL );
216
- FullScreenNotificationIncomingCallModule .sendEventToJs (Constants .RNNotificationEndCallAction ,params );
217
- stopForeground (true );
218
- }
219
- }
220
- }
221
- };
222
187
private int getResourceIdForResourceName (Context context , String resourceName ) {
223
188
int resourceId = context .getResources ().getIdentifier (resourceName , "drawable" , context .getPackageName ());
224
189
if (resourceId == 0 ) {
0 commit comments