BackendlessFCMService

Hi, i have notification in my android app. i setup it successfully and get notification as i want. but i want to manage our notification and save it in local database so i want to get body of notification in a service. i get this line after any receive of notification:

I/BackendlessFCMService: Notification has been received by default ‘BackendlessFCMService’ class. You may override this method in a custom fcm service class which extends from ‘com.backendless.push.BackendlessFCMService’. The notification payload can be found within intent extras: msgIntent.getStringExtra(PublishOptions.<CONSTANT_VALUE>).

… So, i created a class and extends from BackendlessFCMService and overrides onMessage method and add my service in manifest, but i can’t get in my code in custom service, help me just show a toast, rest of it is with us, haaah… thank you for your help.

manifest:





    <service android:name=".ui.notification.NotificationService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

NotificationService:

import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import com.backendless.push.BackendlessFCMService;

public class NotificationService extends BackendlessFCMService {

@Override
public void onCreate() {
    super.onCreate();
    android.os.Debug.waitForDebugger();
}

@Override
public boolean onMessage(Context appContext, Intent msgIntent) {
    Toast.makeText(appContext, "Hey You!", Toast.LENGTH_LONG).show();
    return super.onMessage(appContext, msgIntent);
}

public NotificationService() {
    super();
}

}

Hi, morteza.
At first sight your are doing everything right.

Try to rewrite the method in such way and post here the result.

@Override
public boolean onMessage(Context appContext, Intent msgIntent) {
    Log.i( "NotificationService", msgIntent.getStringExtra(PublishOptions.<CONSTANT_VALUE>));
    return true;
}

what is this?
CONSTANT_VALUE

Hi @morteza-hosseini

PublishOptions.TEMPLATE_NAME, ANDROID_IMMEDIATE_PUSH, IOS_IMMEDIATE_PUSH, INLINE_REPLY, NOTIFICATION_ID, MESSAGE_ID, MESSAGE_TAG…

Hi, thank you. I will test it and report result.

Hi, i found the solution. i created my custom service and add it in manifest:

<service android:name=".ui.notification.NotificationService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
</service>

also, add backendless service in manifest:

<service android:name="com.backendless.push.BackendlessFCMService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
</service>

I removed backendless service from manifest and after that i can get log in my custom service. thank you.

Notice: if anyone wants to debug a service, put this code before any line with breakpoint:

if (BuildConfig.DEBUG)
            android.os.Debug.waitForDebugger();
1 Like