MyFirebaseMessagingService

3,325 views
Skip to first unread message

Dylan

unread,
Mar 26, 2018, 3:24:53 PM3/26/18
to Firebase Google Group
I have been following the guide at https://firebase.google.com/docs/cloud-messaging/android/client?authuser=0 exactly and can't get past the following section ..

<!-- [START firebase_service] -->
<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<!-- [END firebase_service] -->
<!-- [START firebase_iid_service] -->
<service
android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<!-- [END firebase_iid_service] -->

I get Unresolved class 'MyFirebaseMessagingService' and Unresolved class 'MyFirebaseInstanceIDService'

I can't find anywhere in the guidelines where these classes are created although in other forums I see that users are creating them manually. 

The Android Studio (v3.0.1) Firebase - Cloud Messaging 'wizard' doesn't mention anything about this step at all.

Am I missing a step in the procedure to integrate FCM Messaging?


Victor Jimbei

unread,
Mar 27, 2018, 10:10:04 AM3/27/18
to Firebase Google Group
Hi Dylan, 

You'll have to create this two classes and override required methods.

MyFirebaseInstanceIDService extends FirebaseInstanceIdService
and 
MyFirebaseMessagingService extends FirebaseMessagingService

Regards,
Victor

Dylan

unread,
Apr 4, 2018, 10:19:16 AM4/4/18
to Firebase Google Group
Thanks Victor, I have had some success following your advice but have not come up against some more errors. When I use this code from FCM for the "public class MyFirebaseMessagingService extends FirebaseMessagingService {" I get errors on:

import android.app.NotificationChannel; (cannot resolve symbol 'NotificationChannel')
import com.firebase.jobdispatcher.Constraint; (cannot resolve symbol 'firebase')
import com.firebase.jobdispatcher.FirebaseJobDispatcher; (cannot resolve symbol 'firebase')
import com.firebase.jobdispatcher.GooglePlayDriver; (cannot resolve symbol 'firebase')
import com.firebase.jobdispatcher.Job; (cannot resolve symbol 'firebase')

scheduleJob(); (cannot resolve method 'scheduleJob')
handleNow(); (cannot resolve method 'handleNow')

The full content of the java file is posted below ...

package dmsech.dmsapps;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import com.firebase.jobdispatcher.Constraint;
import com.firebase.jobdispatcher.FirebaseJobDispatcher;
import com.firebase.jobdispatcher.GooglePlayDriver;
import com.firebase.jobdispatcher.Job;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

public class MyFirebaseMessagingService extends FirebaseMessagingService {

private static final String TAG = "MyFirebaseMsgService";

/**
* Called when message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// [START_EXCLUDE]
// There are two types of messages data messages and notification messages. Data messages are handled
// here in onMessageReceived whether the app is in the foreground or background. Data messages are the type
// traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app
// is in the foreground. When the app is in the background an automatically generated notification is displayed.
// When the user taps on the notification they are returned to the app. Messages containing both notification
// and data payloads are treated as notification messages. The Firebase console always sends notification
// messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options
// [END_EXCLUDE]

// TODO(developer): Handle FCM messages here.
// Not getting messages here? See why this may be: https://goo.gl/39bRNJ
Log.d(TAG, "From: " + remoteMessage.getFrom());

// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());

if (/* Check if data needs to be processed by long running job */ true) {
// For long-running tasks (10 seconds or more) use Firebase Job Dispatcher.
scheduleJob();
} else {
// Handle message within 10 seconds
handleNow();
}

}

// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}

// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated. See sendNotification method below.
}
// [END receive_message]

Ian Barber

unread,
Apr 4, 2018, 12:43:01 PM4/4/18
to Firebase Google Group
Job Dispatcher is a separate library, you need to include the library in your gradle file: 
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'




--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/ede3c5e9-21fb-44fe-8c25-1c7a20c79d29%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages