Last active
October 12, 2018 09:50
-
-
Save jirawatee/9384c2ac34ada530fe75e831e089269d to your computer and use it in GitHub Desktop.
FCM - MyFirebaseInstanceIDService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.fcm; | |
import android.util.Log; | |
import com.google.firebase.iid.FirebaseInstanceId; | |
import com.google.firebase.iid.FirebaseInstanceIdService; | |
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService { | |
private static final String TAG = "MyFirebaseIIDService"; | |
/** | |
* Called if InstanceID token is updated. This may occur if the security of | |
* the previous token had been compromised. Note that this is called when the InstanceID token | |
* is initially generated so this is where you would retrieve the token. | |
*/ | |
@Override | |
public void onTokenRefresh() { | |
super.onTokenRefresh(); | |
String refreshedToken = FirebaseInstanceId.getInstance().getToken(); | |
Log.d(TAG, "Refreshed token: " + refreshedToken); | |
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(String token) { | |
// Add custom implementation, as needed. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment