Skip to content

Instantly share code, notes, and snippets.

@javieranton-zz
Created May 12, 2020 20:23
Show Gist options
  • Select an option

  • Save javieranton-zz/821455be02cf9e899b98f609152e99d4 to your computer and use it in GitHub Desktop.

Select an option

Save javieranton-zz/821455be02cf9e899b98f609152e99d4 to your computer and use it in GitHub Desktop.
String token = com.google.firebase.iid.FirebaseInstanceId.getInstance().getToken();
if (token != null) {
com.codename1.io.Preferences.set("pushKey", token);
your.app.namespace.SomeClass.SomeStaticMethod(token); }
//check token is the same after 5 seconds
//cn1's gcm service sometimes gets the wrong token and this is then useful to overwrite it
java.util.Timer timer = new java.util.Timer();
timer.schedule(new java.util.TimerTask() {
public void run() {
Display.getInstance().callSerially(new Runnable() {
public void run() {
String token = com.google.firebase.iid.FirebaseInstanceId.getInstance().getToken();
if (token != null && !(token).equals(com.codename1.io.Preferences.get("pushKey", ""))) {
com.codename1.io.Preferences.set("pushKey",token);
your.app.namespace.SomeClass.SomeStaticMethod(token);
}
}
});
}
}, 5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment