I’m working on an android project where I’ve to use FCM push notifications. Since legacy API is going to be removed in the coming days, I used FCM with Http v1 Oauth2 Access Tokens. It worked correctly to send a notification from Android 12 (API 32), but not from Android 4.4 (API 19). Both are physical devices. API 19 device received it successfully when the other device sent it, so FirebaseMessagingService is definitely working on it. The only problem is to send a notification from API 19 (and potentially all devices under API 26).
The error that I have is in the following block:-
private static String getAccessToken() throws IOException {
GoogleCredentials googleCredentials = GoogleCredentials
.fromStream(stream) // This line produces error
.createScoped(Arrays.asList(SCOPES));
googleCredentials.refresh();
return googleCredentials.getAccessToken().getTokenValue();
}
The error produced is NoClassDefFoundError: java.lang.Duration
I understand the error in itself, but Duration class was only added in API 26. GoogleCredentials class uses Duration class under the hood.
So my question essentially comes down to this: How to send the FCM notification on devices under API 26 (preferably till 19)? If it is not possible, does it mean that FCM Push notifications are only going to be available for devices which have at least API 26?
Thanks in advance
user25347399 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.