Can't See Token In Logcat For Firebase Push Notification App
Solution 1:
If you are using Wifi Network may be google API won't work. If it is so then ask admin person then you are good to go.
May be you are not getting the Log only try to copy and past the TAG in Log filter or your IDE then check for the Log.
If you are getting then save into SharedPrefernce or upload to the server.
Solution 2:
ublic classMyFirebaseInstanceIDServiceextendsFirebaseInstanceIdService {
privatestatic final StringTAG = "MyFirebaseIIDService";
@OverridepublicvoidonTokenRefresh() {
// Get updated InstanceID token.String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
// If you want to send messages to this application instance or// manage this apps subscriptions on the server side, send the// Instance ID token to your app server.//call this sendRegistrationToServer(refreshedToken);
}
privatevoidsendRegistrationToServer(String token) {
// TODO: Implement this method to send token to your app server.
}
}
You need to just use the receiver extending the FirebaseInstanceIdService and you can search in debug log with "Refreshed token:" tag and your token can be seen. Make sure you make a fresh launch because token is not refreshed every time you launches the app.
Solution 3:
please refer this, may be it can be useful
call sendRegistrationToServer(refreshedToken)
cal this in onTokenRefresh()
method
publicclassMyFirebaseInstanceIDServiceextendsFirebaseInstanceIdService {
privatestatic final StringTAG = "MyFirebaseIIDService";
@OverridepublicvoidonTokenRefresh() {
// Get updated InstanceID token.String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
// If you want to send messages to this application instance or// manage this apps subscriptions on the server side, send the// Instance ID token to your app server.//call this sendRegistrationToServer(refreshedToken);
}
privatevoidsendRegistrationToServer(String token) {
// TODO: Implement this method to send token to your app server.
}
}
In MAinActivity.java add this in oncreate(),
if (getIntent().getExtras() != null) {
for (String key : getIntent().getExtras().keySet()) {
Object value = getIntent().getExtras().get(key);
Log.d(TAG, "Key: " + key + " Value: " + value);
}
}
String token = FirebaseInstanceId.getInstance().getToken();
System.out.println("========== PUSH ID ========" + token);
Toast.makeText(MainActivity.this, "PUSH ID :::" + token, Toast.LENGTH_SHORT).show();
Solution 4:
You can use SharedPreferences
. First of all define new method called storeRegIdInPref
in your MyFirebaseInstanceIDService
class and call in onTokenRefresh
method.
privatevoidstoreRegIdInPref(String token) {
SharedPreferences pref = getApplicationContext().getSharedPreferences("my_pref", 0);
pref.edit().putString("regId", token).apply();
}
Then, get the preferences in your MainActivity
using this method:
privatevoiddisplayRegID() {
SharedPreferencespref= getApplicationContext().getSharedPreferences("my_pref", 0);
StringregId= pref.getString("regId", null);
Log.i(TAG, "Firebase Registration ID: " + regId);
}
Call that method in onCreate
.
Solution 5:
Try uninstalling the app and running it again, i also had the same problem and this method worked for me.
Post a Comment for "Can't See Token In Logcat For Firebase Push Notification App"