When calling another user, call notification doesn’t come, whereas other notifications like text message notification and group notifications are coming fine.
I’ve parsed the notification response with BaseMessage.processmessage too, kindly provide a viable solution to this…
Hello @vavci
Can you please share the code snippet you are using to initiate the call.
Also, please share the code for the onMessageReceived()
method of the FirebaseMessagingService class so that we can check if everything is implemented correctly at your end.
Thanks
Hi,
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
try {
BaseMessage baseMessage = BaseMessage.processMessage(new JSONObject(remoteMessage.getData().get(“message”)));
if (baseMessage.getCategory().equalsIgnoreCase(“call”)) {
Intent callIntent = new Intent(getApplicationContext(), CallActivity.class);
callIntent.putExtra(StringContract.IntentString.Companion.getUSER_NAME(), baseMessage.getSender().getName());
callIntent.putExtra(StringContract.IntentString.Companion.getSESSION_ID(), baseMessage.getSessionId());
callIntent.putExtra(StringContract.IntentString.Companion.getUSER_ID(), baseMessage.getSender().getUid());
callIntent.putExtra(StringContract.IntentString.Companion.getUSER_AVATAR(), baseMessage.getSender().getAvatar());
callIntent.putExtra(StringContract.IntentString.Companion.getRECIVER_TYPE(), CometChatConstants.RECEIVER_TYPE_USER);
callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
callIntent.setAction(baseMessage.getType());
callIntent.setType(StringContract.IntentString.Companion.getINCOMING());
startActivity(callIntent);
}
}
Hi @vavci,
From the above code, it seems like you are not creating a notification for your call message. You need to create a notification whenever you receive a call.
Please refer the below MyFirebaseMessagingService.class
Also, you need to use BroadcastReceiver to accept & reject the call using push notification.
Please refer the below CallNotificationAction.java
.
We’ve made custom class for CallActivity which works absolutely fine when we are on the chat screen,
CODE:
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
try {
json = new JSONObject(remoteMessage.getData());
JSONObject messageData = new JSONObject(json.getString("message"));
CustomLog.e(TAG, "From: " + remoteMessage.getData().toString());
if (remoteMessage.getData().get("message") != null) {
BaseMessage baseMessage = CometChatHelper.processMessage(new JSONObject(remoteMessage.getData().get("message")));
if (baseMessage instanceof Call) {
call = (Call) baseMessage;
isCall = true;
showNotifcation();
} else {
sendCometNotification(baseMessage.getCategory(), baseMessage.getSender().getName(), baseMessage.getId(), baseMessage.getSender().getUid());
}
}
} catch (Exception e) {
CustomLog.e(e);
}
}
private void sendCometNotification(String messageBody, String title, int id, String
recieverId) {
try {
if (recieverId != null) {
getUserdata(recieverId);
}
NotificationChannel mChannel;
NotificationManager notifManager = (NotificationManager) getSystemService
(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(this, CometMainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, id /* Request code */, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mChannel = new NotificationChannel
("0", title, NotificationManager.IMPORTANCE_HIGH);
mChannel.setDescription(messageBody);
mChannel.enableVibration(true);
notifManager.createNotificationChannel(mChannel);
//}
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "0");
pendingIntent = PendingIntent.getActivity(this, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentTitle(title)
.setSmallIcon(R.mipmap.ic_launcher2) // required
.setContentText(messageBody) // required
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setGroup(GROUP_KEY)
.setGroupSummary(true)
.setSound(RingtoneManager.getDefaultUri
(RingtoneManager.TYPE_NOTIFICATION));
Notification notification = builder.build();
notifManager.notify(id, notification);
} else {
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setContentTitle(title)
.setContentText(messageBody)
.setAutoCancel(true)
.setColor(ContextCompat.getColor(getBaseContext(), R.color.colorPrimary))
.setSound(defaultSoundUri)
.setSmallIcon(getNotificationIcon())
.setContentIntent(pendingIntent)
.setStyle(new NotificationCompat.BigTextStyle().setBigContentTitle(title).bigText(messageBody));
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(id, notificationBuilder.build());
}
} catch (Exception e) {
CustomLog.e(e);
}
}
private void showNotifcation() {
try {
if (json.getString(“alert”).equals(“Incoming audio call”) || json.getString(“alert”).equals(“Incoming video call”)) {
Intent callIntent = new Intent(getApplicationContext(), CallActivity.class);
callIntent.putExtra(StringContract.IntentString.Companion.getUSER_NAME(), call.getSender().getName());
callIntent.putExtra(StringContract.IntentString.Companion.getUSER_ID(), call.getSender().getUid());
callIntent.putExtra(StringContract.IntentString.Companion.getSESSION_ID(), call.getSessionId());
callIntent.putExtra(StringContract.IntentString.Companion.getUSER_AVATAR(), call.getSender().getAvatar());
callIntent.putExtra(StringContract.IntentString.Companion.getRECIVER_TYPE(), CometChatConstants.RECEIVER_TYPE_USER);
callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
callIntent.setAction(call.getType());
callIntent.setType(StringContract.IntentString.Companion.getINCOMING());
startActivity(callIntent);
}
} catch (Exception e) {
CustomLog.e(e);
}
}
It is working fine on some devices, but on some devices it shows a notification with “hello message” thus the notification not being an instance of ‘Call’
Hi @vavci,
From the code above it seems like you are not creating the notification for call messages. As we can’t see any Notification Builder
used in showNotification()
method of your code. So you won’t be able to receive a call notification. You are trying to start CallActivity.java
from firebase service class which is not feasible. You need to create a notification and through the actions of notification, you need to accept and reject the call.
Please refer to the code mentioned in this post.
Also visit the below link to know restrictions on calling activities from background.
https://developer.android.com/guide/components/activities/background-starts
The call is not coming when the app is in Background or app is not open (killed).
If my phone is locked, then also audio and video calls not coming.
Can anyone please reply??
We have a release scheduled Tomorrow and due to this high priority issue we may have to postpone and our client is highly irritated due to the fault.
Hello @vavci
As mentioned, if you are checking on android 10, there have been restrictions added by Android to start activities when the app is in background. Please make sure you go through the below link
https://developer.android.com/guide/components/activities/background-starts
From what we observe in your code, it seems you are not creating a notification when a call notification is received.
You need to create a notifiction to display and based on that start the call screen.
Hope this helps
We have already done this in our code now.
Can you please check via Team viewer … ?
This is getting critical for us.
Hello @vavci
Can you please visit the CometChat dashboard and initiate a conversation there by chlicking the chat button at the bottom right of the page.We can take it real time from there
Thanks
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.