0

I'm working on a patient-doctor call app using firebase notification.

When patient clicks on call button, the doctor should receive notification and the app should come in front whether the screen was off or app was in background.

Right now, when we send firebase notification, doctor has to click on the notification to open the app. The problem is, doctors don't look at the phone all the time and they say they did not get any notification.

I know app can be opened implicitly without user intervension as I'm using similar kind of another app.

I tried this code:

public class MyFirebaseMessagingService extends FirebaseMessagingService {
  @Override
  public void onMessageReceived(RemoteMessage remoteMessage) {
    if (remoteMessage.getData().size() > 0) {
      Intent intent = new Intent(this, MainActivity.class);
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

      PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

      NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "channel_id")
        .setSmallIcon(R.drawable.notification_icon)
        .setContentTitle(remoteMessage.getData().get("title"))
        .setContentText(remoteMessage.getData().get("message"))
        .setAutoCancel(true)
        .setContentIntent(pendingIntent);
  
        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
  manager.notify(0, builder.build());
 }
 }
}

What am I missing?

Ashutosh
  • 4,371
  • 10
  • 59
  • 105
  • "the app should come in front whether the screen was off or app was in background" -- that is not an option in general on modern versions of Android. See [the documentation](https://developer.android.com/guide/components/activities/background-starts) for more. – CommonsWare Feb 08 '23 at 18:52
  • I'm using a society app. When someone comes at gate, guard enters their details and app on my phone automatically pops up with person details – Ashutosh Feb 08 '23 at 18:54

0 Answers0