use of com.google.android.gms.iid.InstanceID in project IITB-App by wncc.
the class RegistrationIntentService method onHandleIntent.
@RequiresApi(api = Build.VERSION_CODES.GINGERBREAD)
@Override
protected void onHandleIntent(@Nullable Intent intent) {
String token = null;
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
try {
InstanceID instanceID = InstanceID.getInstance(this);
token = instanceID.getToken("306601329049", GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
Log.i(TAG, "GCM Registration Token: " + token);
Toast.makeText(this, "GCM Registration Token: " + token, Toast.LENGTH_SHORT).show();
sharedPreferences.edit().putBoolean(SENT_TOKEN_TO_SERVER, true).apply();
} catch (Exception e) {
Log.d(TAG, "Failed to complete token refresh", e);
sharedPreferences.edit().putBoolean(SENT_TOKEN_TO_SERVER, false).apply();
}
// Notify UI that registration is complete
Intent registrationComplete = new Intent(REGISTRATION_COMPLETE);
registrationComplete.putExtra("Token", token);
LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
}
use of com.google.android.gms.iid.InstanceID in project android-oss by kickstarter.
the class RegisterService method onHandleIntent.
@Override
protected void onHandleIntent(@NonNull final Intent intent) {
Timber.d("onHandleIntent");
try {
// This initially hits the network to retrieve the token, subsequent calls are local
final InstanceID instanceID = InstanceID.getInstance(this);
// R.string.gcm_defaultSenderId is derived from google-services.json
final String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
Timber.d("Token: %s", token);
sendTokenToApi(token);
subscribeToGlobalTopic(token);
} catch (final Exception e) {
Timber.e("Failed to complete token refresh: %s", e);
}
}
use of com.google.android.gms.iid.InstanceID in project android-oss by kickstarter.
the class UnregisterService method onHandleIntent.
@Override
protected void onHandleIntent(@NonNull final Intent intent) {
Timber.d("onHandleIntent");
try {
final InstanceID instanceID = InstanceID.getInstance(this);
instanceID.deleteToken(getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE);
Timber.d("Deleted token");
} catch (final Exception e) {
Timber.e("Failed to delete token: %s", e);
}
}
use of com.google.android.gms.iid.InstanceID in project FastGCM by iammert.
the class RegistrationService method onHandleIntent.
/**
* This Intent is responsible for get token from GCM server and send
* broadcast. After we get token, we save this token to shared preferences.
* @param intent
*/
@Override
protected void onHandleIntent(Intent intent) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
try {
InstanceID instanceID = InstanceID.getInstance(this);
String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
sharedPreferences.edit().putBoolean(Constants.SHARED_KEY_HAS_TOKEN, true).apply();
sharedPreferences.edit().putString(Constants.SHARED_KEY_TOKEN, token).apply();
} catch (Exception e) {
sharedPreferences.edit().putBoolean(Constants.SHARED_KEY_HAS_TOKEN, false).apply();
}
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(Constants.INTENT_REGISTRATION_COMPLETE));
}
use of com.google.android.gms.iid.InstanceID in project phonegap-plugin-push by phonegap.
the class RegistrationIntentService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences(COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE);
try {
InstanceID instanceID = InstanceID.getInstance(this);
String senderID = sharedPreferences.getString(SENDER_ID, "");
String token = instanceID.getToken(senderID, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
PushPlugin.setRegistrationID(token);
Log.i(LOG_TAG, "new GCM Registration Token: " + token);
} catch (Exception e) {
Log.d(LOG_TAG, "Failed to complete token refresh", e);
}
}
Aggregations