0

I've done the step by step in the tutorial, get json, adding dependecies (classpath 'com.google.gms:google-services:3.0.0'),
apply plugin (apply plugin: 'com.google.gms.google-services'), modify manifest file. (Don't forget to put these into application, not outside it!)

<service android:name=".MyFirebaseMessagingService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT"/>
    </intent-filter>
</service>
<service android:name=".FirebaseIDService">
    <intent-filter>
        <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
    </intent-filter>
</service>

create firebaseMessagingService Class (MyFirebaseMessagingService.java)

public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "FCM Service";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // TODO: Handle FCM messages here.
    // If the application is in the foreground handle both data and notification messages here.
    // Also if you intend on generating your own notifications as a result of a received FCM
    // message, here is where that should be initiated.
    Log.d(TAG, "From: " + remoteMessage.getFrom());
    Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
}
}

creating FirebaseIDService.java that extends FirebaseInstanceIdService

public class FirebaseIDService extends FirebaseInstanceIdService {
private static final String TAG = "FirebaseIDService";

@Override
public void onTokenRefresh() {
    // Get updated InstanceID token.
    String refreshedToken = FirebaseInstanceId.getInstance().getToken();
    Log.d(TAG, "Refreshed token: " + refreshedToken);

    // TODO: Implement this method to send any registration to your app's servers.
    sendRegistrationToServer(refreshedToken);
}

/**
 * Persist token to third-party servers.
 *
 * Modify this method to associate the user's FCM InstanceID token with any server-side account
 * maintained by your application.
 *
 * @param token The new token.
 */
private void sendRegistrationToServer() {
    // Add custom implementation, as needed.
    String refreshedToken = FirebaseInstanceId.getInstance().getToken();
    Log.d(TAG, "Refreshed token: " + refreshedToken);
}
}

Here my main activity class snippet:

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    //FCM
    FirebaseIDService firebaseIDService = new FirebaseIDService();
    MyFirebaseMessagingService myFirebaseMessagingService = new MyFirebaseMessagingService();

Then I send the push notification from console, but nothing happens. What part is missing? or something is not working? I dunt get any logcat info from both class i create

UPDATE: this what i did to fix the Firebase not linked issue: I need to call the class manually and get token, and its working

FirebaseIDService firebaseIDService = new FirebaseIDService();
    firebaseIDService.getId();

But somehow, the push notification still not coming, the FCM class i used not giving any logcat, any idea?

UPDATE: so far i dunt find solution yet on receiving the message. the class that extends FirebaseMessagingService still not working, not showing anything in logcat, but it does showing something like this: D/FA: Logging event (FE): _nf, Bundle[{_o=fcm, _ndt=0, _nmn=Bayu testing PN, _nmt=1492745322, _nmid=2820998932030178856}]

Gabriel
  • 229
  • 4
  • 19
  • Have you get refreshToken in logcat ? @Bayu Wibawa – Rujul Gandhi Apr 20 '17 at 07:38
  • No, it wont show that in logcat, my mainactivity class is correct,no ? i just need to create the class on mainactivity to run onTokenRefresh function, right? – Gabriel Apr 20 '17 at 07:48
  • Remove your `FirebaseIDService firebaseIDService = new FirebaseIDService(); MyFirebaseMessagingService myFirebaseMessagingService = new MyFirebaseMessagingService();` lines from mainActivity because it willl automatically called.. – Rujul Gandhi Apr 20 '17 at 07:49
  • i remove it, somehow i found this on logcat: D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization. Why is that? is this cause the error? – Gabriel Apr 20 '17 at 07:57
  • The codes look okay. Are you positive that you're sending the message to the correct registration token? – AL. Apr 20 '17 at 08:45
  • i got the token, its very long string, like this: eKifiKFRQf8:APA91bGSwWpH5ziyM_HToeup_K98lZlbL0ivEedZZ-0g3wLnJlXt36yesY6yvWjlaS3mK3R6cZghE4a8dm5EwtY1BARo9t1Ctx4E0L0NMN-xXTi-vvskP1ll10mX0xLyDs7Jvw1kjCrT – Gabriel Apr 20 '17 at 08:50
  • so far i dunt find solution yet on receiving the message. the class that extends FirebaseMessagingService still not working, not showing anything in logcat, but it does showing something like this: D/FA: Logging event (FE): _nf, Bundle[{_o=fcm, _ndt=0, _nmn=Bayu testing PN, _nmt=1492745322, _nmid=2820998932030178856}] – Gabriel Apr 21 '17 at 03:34

2 Answers2

1

I have it working now, the issue is because i put service outside of the application, so the services must inside the application, so the onReceivedMessage will work

Gabriel
  • 229
  • 4
  • 19
  • Please consider updating the question with the portion of the wrong manifest, and explain in the answer what was the error. So a future reader can learn from this question. – Diego Giorgini Apr 22 '17 at 00:59
0

You probably skipped this step, since i don't see you mentioned it:
In your module Gradle file (usually the app/build.gradle), add the apply plugin line at the bottom of the file to enable the Gradle plugin:

apply plugin: 'com.android.application'

android {
  // ...
}

dependencies {
  // ...
  compile 'com.google.firebase:firebase-core:10.2.1'

  // Getting a "Could not find" error? Make sure you have
  // the latest Google Repository in the Android SDK manager
}

// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'

Please note the: compile 'com.google.firebase:firebase-core:10.2.1'

Mercury
  • 7,430
  • 3
  • 42
  • 54
  • i forgot to mention that, i added these 2 lines: compile 'com.google.firebase:firebase-core:9.2.0' compile 'com.google.firebase:firebase-messaging:9.2.0', but when i try change into 10.2.1 it getting error – Gabriel Apr 20 '17 at 08:07
  • Change the version number to whatever you need, if you get error please post the error here please – Mercury Apr 20 '17 at 08:15