I am using following code to send the FCM notification from server to device :
String fcmServerKey = externalConfig.getFcmServerKey();
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(HTTPS_FCM_GOOGLEAPIS_COM_FCM_SEND);
httpPost.setEntity(new StringEntity(message, ContentType.create("application/json")));
httpPost.setHeader("Authorization", "key=" + fcmServerKey);
CloseableHttpResponse closeableHttpResponse= httpclient.execute(httpPost);
In above code when I get the response object closeableHttpResponse
, how can I detect wether the fcm token used to send this request is expired or not registered ?
When from firebase application dashboard I try sending the notification to a device using its fcm token and After application is removed from device, I see Failed
on firebase dashboard, on hovering cursor on Failed
I see Unregistered registration token
.
How can I detect above error situation of Unregistered registration token
from api response object closeableHttpResponse
?
It doesn't expire though. It renews itself if one of the following happens. According to https://firebase.google.com/docs/cloud-messaging/android/client: -The app deletes Instance ID.
The message expires The maximum time that FCM will retry is 28 days, which is the default value.
FCM token for an app may change due to various reasons that are specified in the Firebase documentation.
Use the Server Reference API to get the associated information about the device registration token. If the response is empty, it means that the token is expired or not registered.
Example GET request
https://iid.googleapis.com/iid/info/nKctODamlM4:...clJONHoA?details=true
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
Example result
HTTP 200 OK
{
"application":"com.iid.example",
"authorizedEntity":"123456782354",
"platform":"Android",
"attestStatus":"ROOTED",
"appSigner":"1a2bc3d4e5",
"connectionType":"WIFI",
"connectDate":"2015-05-12
"rel":{
"topics":{
"topicname1":{"addDate":"2015-07-30"},
"topicname2":{"addDate":"2015-07-30"},
"topicname3":{"addDate":"2015-07-30"},
"topicname4":{"addDate":"2015-07-30"}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With