Sich client id was created and FCM google json files were also added
But it not working
private class SinchCallControllerListener implements CallControllerListener {
@Override
public void onIncomingCall(CallController callClient, Call call) {
Log.d(TAG, "onIncomingCall: " + call.getCallId());
Intent intent = new Intent(SinchService.this, IncomingCallScreenActivity.class);
intent.putExtra(EXTRA_ID, MESSAGE_ID);
intent.putExtra(CALL_ID, call.getCallId());
boolean inForeground = isAppOnForeground(getApplicationContext());
if (!inForeground) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
} else {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && !inForeground) {
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(
MESSAGE_ID, createIncomingCallNotification(call.getRemoteUserId(), intent));
} else {
SinchService.this.startActivity(intent);
}
}
private boolean isAppOnForeground(Context context) {
ActivityManager activityManager =
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> appProcesses =
activityManager.getRunningAppProcesses();
if (appProcesses == null) {
return false;
}
final String packageName = context.getPackageName();
for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
if (appProcess.importance
== ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
&& appProcess.processName.equals(packageName)) {
return true;
}
}
return false;
}
private Bitmap getBitmap(Context context, int resId) {
int largeIconWidth = (int) context.getResources()
.getDimension(R.dimen.notification_large_icon_width);
int largeIconHeight = (int) context.getResources()
.getDimension(R.dimen.notification_large_icon_height);
Drawable d = context.getResources().getDrawable(resId);
Bitmap b =
Bitmap.createBitmap(largeIconWidth, largeIconHeight, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
d.setBounds(0, 0, largeIconWidth, largeIconHeight);
d.draw(c);
return b;
}
private PendingIntent getPendingIntent(Intent intent, String action) {
intent.setAction(action);
PendingIntent pendingIntent =
PendingIntent.getActivity(getApplicationContext(), 111, intent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
return pendingIntent;
}
@TargetApi(29)
private Notification createIncomingCallNotification(String userId,
Intent fullScreenIntent) {
PendingIntent pendingIntent =
PendingIntent.getActivity(getApplicationContext(), 112, fullScreenIntent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
NotificationCompat.Builder builder =
new NotificationCompat.Builder(getApplicationContext(),
FcmListenerService.CHANNEL_ID)
.setContentTitle("Incoming call")
.setContentText(userId)
.setLargeIcon(getBitmap(getApplicationContext(), R.drawable.icon))
.setSmallIcon(R.drawable.icon)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setContentIntent(pendingIntent)
.setFullScreenIntent(pendingIntent, true)
.addAction(R.drawable.button_accept, "Answer",
getPendingIntent(fullScreenIntent, ACTION_ANSWER))
.addAction(R.drawable.button_decline, "Ignore",
getPendingIntent(fullScreenIntent, ACTION_IGNORE))
.setOngoing(true);
return builder.build();
}
}[](https://i.stack.imgur.com/6nHGg.png)
Expected result: Getting incoming call between the two users (or) give the proper documentation for implement the sinch in android
Sinch sdk link : https://developers.sinch.com/docs/in-app-calling/sdk-downloads/