Skip to content

Instantly share code, notes, and snippets.

@progress44
Created August 11, 2016 09:18
Show Gist options
  • Save progress44/5b1e910776274744ad71f9b5c340fef7 to your computer and use it in GitHub Desktop.
Save progress44/5b1e910776274744ad71f9b5c340fef7 to your computer and use it in GitHub Desktop.
if (senderId != null) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
String token = getToken(senderId);
GcmPubSub.getInstance(TiApplication.getInstance()).subscribe(token, topic, null);
if (successTopicCallback != null) {
// send success callback
HashMap<String, Object> data = new HashMap<String, Object>();
data.put("success", true);
data.put("topic", topic);
successTopicCallback.callAsync(getKrollObject(), data);
}
} catch (Exception ex) {
// error
Log.e(LCAT, "Error " + ex.toString());
if (errorTopicCallback != null) {
// send error callback
HashMap<String, Object> data = new HashMap<String, Object>();
data.put("success", false);
data.put("topic", topic);
data.put("error", ex.toString());
errorCallback.callAsync(getKrollObject(), data);
}
}
return null;
}
}.execute();
} else {
sendError(errorTopicCallback, "No GCM senderId specified; get it from the Google Play Developer Console");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment