use of com.google.android.gms.iid.InstanceID in project Conversations by siacs.
the class PushManagementService method retrieveGcmInstanceToken.
private void retrieveGcmInstanceToken(final OnGcmInstanceTokenRetrieved instanceTokenRetrieved) {
new Thread(new Runnable() {
@Override
public void run() {
InstanceID instanceID = InstanceID.getInstance(mXmppConnectionService);
try {
String token = instanceID.getToken(mXmppConnectionService.getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
instanceTokenRetrieved.onGcmInstanceTokenRetrieved(token);
} catch (Exception e) {
Log.d(Config.LOGTAG, "unable to get push token");
}
}
}).start();
}
use of com.google.android.gms.iid.InstanceID in project iosched by google.
the class GCMRegistrationIntentService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
try {
InstanceID instanceID = InstanceID.getInstance(this);
String token = instanceID.getToken(BuildConfig.GCM_SENDER_ID, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
// server can send user specific messages.
if (AccountUtils.hasActiveAccount(this)) {
// Get the correct GCM key for the user. GCM key is a somewhat non-standard
// approach we use in this app. For more about this, check GCM.TXT.
final String gcmKey = AccountUtils.hasActiveAccount(this) ? AccountUtils.getGcmKey(this, AccountUtils.getActiveAccountName(this)) : null;
sendRegistrationToServer(token, gcmKey);
}
subscribeTopics(token);
} catch (IOException e) {
LOGE(TAG, "An exception occurred generating InstanceID token: " + e.getMessage());
}
}
use of com.google.android.gms.iid.InstanceID in project google-services by googlesamples.
the class RegistrationIntentService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
try {
// [START register_for_gcm]
// Initially this call goes out to the network to retrieve the token, subsequent calls
// are local.
// R.string.gcm_defaultSenderId (the Sender ID) is typically derived from google-services.json.
// See https://developers.google.com/cloud-messaging/android/start for details on this file.
// [START get_token]
InstanceID instanceID = InstanceID.getInstance(this);
String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
// [END get_token]
Log.i(TAG, "GCM Registration Token: " + token);
// TODO: Implement this method to send any registration to your app's servers.
sendRegistrationToServer(token);
// Subscribe to topic channels
subscribeTopics(token);
// You should store a boolean that indicates whether the generated token has been
// sent to your server. If the boolean is false, send the token to your server,
// otherwise your server should have already received the token.
sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, true).apply();
// [END register_for_gcm]
} catch (Exception e) {
Log.d(TAG, "Failed to complete token refresh", e);
// If an exception happens while fetching the new token or updating our registration data
// on a third-party server, this ensures that we'll attempt the update at a later time.
sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false).apply();
}
// Notify UI that registration has completed, so the progress indicator can be hidden.
Intent registrationComplete = new Intent(QuickstartPreferences.REGISTRATION_COMPLETE);
LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
}
use of com.google.android.gms.iid.InstanceID in project ETSMobile-Android2 by ApplETS.
the class RegistrationIntentService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
try {
// ensure that they are processed sequentially.x
synchronized (TAG) {
// [START register_for_gcm]
// Initially this call goes out to the network to retrieve the token, subsequent calls
// are local.
// [START get_token]
InstanceID instanceID = InstanceID.getInstance(this);
//TODO put authorized entity in a property file
String token = instanceID.getToken(getString(R.string.google_authorized_entity), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
// [END get_token]
Log.i(TAG, "GCM Registration Token: " + token);
sendRegistrationToServer(token);
// Subscribe to topic channels
subscribeTopics(token);
// You should store a boolean that indicates whether the generated token has been
// sent to your server. If the boolean is false, send the token to your server,
// otherwise your server should have already received the token.
sharedPreferences.edit().putBoolean(Constants.IS_GCM_TOKEN_SENT_TO_SERVER, true).apply();
// [END register_for_gcm]
}
} catch (Exception e) {
Log.d(TAG, "Failed to complete token refresh", e);
// If an exception happens while fetching the new token or updating our registration data
// on a third-party server, this ensures that we'll attempt the update at a later time.
sharedPreferences.edit().putBoolean(Constants.IS_GCM_TOKEN_SENT_TO_SERVER, false).apply();
}
// Notify UI that registration has completed, so the progress indicator can be hidden.
Intent registrationComplete = new Intent(Constants.REGISTRATION_COMPLETE);
LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
}
use of com.google.android.gms.iid.InstanceID in project WordPress-Android by wordpress-mobile.
the class GCMRegistrationIntentService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
try {
InstanceID instanceID = InstanceID.getInstance(this);
String gcmId = BuildConfig.GCM_ID;
if (TextUtils.isEmpty(gcmId)) {
AppLog.e(T.NOTIFS, "GCM_ID must be configured in gradle.properties");
return;
}
String token = instanceID.getToken(gcmId, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
sendRegistrationToken(token);
} catch (Exception e) {
// SecurityException can happen on some devices without Google services (these devices probably strip
// the AndroidManifest.xml and remove unsupported permissions).
AppLog.e(T.NOTIFS, "Google Play Services unavailable: ", e);
}
}
Aggregations