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}]