Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] android – why remoteMessage from FCM dont work in background?

Posted on November 14, 2022

Solution 1 :

When app is in background, onMessageReceived is not called until users taps on notification associated with push message.
If you want the system to call onMessageReceived without user tapping on notification, try to send a silent push message.

Problem :

When i send message from server, only work when app is running in foreground.
I send message with payload and notification body.
if app is running in background onMessageReceived is not called.
what could be failing
My code n Manifest

 <application
        android_largeHeap="true"
        android_allowBackup="true"
        android_icon="@mipmap/ic_launcher"
        android_label="@string/app_name"
       android_usesCleartextTraffic="true">
      <meta-data
            android_name="com.google.firebase.messaging.default_notification_icon"
            android_resource="@drawable/logo_mediano" />
        <meta-data
            android_name="com.google.firebase.messaging.default_notification_color"
            android_resource="@color/colorAccent" />
        <meta-data
            android_name="com.google.firebase.messaging.default_notification_channel_id"
            android_value="@string/default_notification_channel_id"/>
       <service
            android_name=".mackey.FCMService"
            android_enabled="true"
            android_directBootAware="true"
            android_exported="false"

            android_resource="@drawable/ic_menu_camera">
            <intent-filter>
                <action android_name="com.google.firebase.MESSAGING_EVENT" />

            </intent-filter>
        </service>
        </aplication>
        <uses-permission android_name="android.permission.INTERNET" />

My service class:

        public class FCMService extends FirebaseMessagingService {
    private static final String LOGTAG = "android-fcm";

    public FCMService() {
    }
   @Override
    public void onNewToken(String token) {
     sendRegistrationToServer(token);
    }
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        System.out.println("remote message");
     
        if (remoteMessage.getNotification() != null) {

            Log.d(LOGTAG, "NOTIFICATION");
            Log.d(LOGTAG, "Title: " + remoteMessage.getNotification().getTitle());
            
        }

        if(remoteMessage.getData() != null) {
             Log.d(LOGTAG, "DATA");
            Log.d(LOGTAG, "Title php : " + remoteMessage.getData().get("title"));
            Log.d(LOGTAG, "Image: " + remoteMessage.getData().get("image"));
           
        }
    }

graddle Module App

implementation 'com.google.firebase:firebase-messaging:20.2.3'

Logcat in Background:

V/FA: Connecting to remote service
D/FA: Connected to remote service
V/FA: Processing queued up service tasks: 1
I/FirebaseMessaging: Starting download of: https://image.freepik.com/vector-gratis/imagen-tridimensional-coche-taxi-aislado-fondo-blanco_53876-12108.jpg
W/FirebaseMessaging: Notification Channel set in AndroidManifest.xml has not been created by the app. Default value will be used.
V/FA: Inactivity, disconnecting from the service

Logcat in foreground:

I/System.out: remote message
D/android-fcm: NOTIFICATION
D/android-fcm: new Notification
D/android-fcm: DATA
D/android-fcm: Title php : data  php
D/android-fcm: Title php : default
READ  [ANSWERED] javascript - [Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'this.state.result.map')]
Powered by Inline Related Posts

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress