use of com.google.firebase.iid.InstanceIdResult in project ETSMobile-Android2 by ApplETS.
the class FcmRegistrationIntentService method onHandleWork.
@Override
public void onHandleWork(@NonNull Intent intent) {
// [START get_token]
try {
Task<InstanceIdResult> instanceId = FirebaseInstanceId.getInstance().getInstanceId();
InstanceIdResult result = Tasks.await(instanceId);
Log.i(TAG, "FCM Registration Token: " + result.getToken());
if (ApplicationManager.domaine != null && ApplicationManager.userCredentials != null) {
sendRegistrationToServer(result.getToken());
// Subscribe to topic channels
subscribeTopics();
// [END get_token]
// 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);
// [END register_for_fcm]
}
} catch (ExecutionException | InterruptedException ei) {
ei.printStackTrace();
}
}
use of com.google.firebase.iid.InstanceIdResult in project zype-android by zype.
the class ZypeApp method getPinpointManager.
public static PinpointManager getPinpointManager(Context context) {
if (pinpointManager == null || TextUtils.isEmpty(pinpointManager.getNotificationClient().getDeviceToken())) {
PinpointConfiguration pinpointConfig = new PinpointConfiguration(context.getApplicationContext(), AWSMobileClient.getInstance().getCredentialsProvider(), AWSMobileClient.getInstance().getConfiguration());
pinpointManager = new PinpointManager(pinpointConfig);
FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
@Override
public void onComplete(@NonNull Task<InstanceIdResult> task) {
if (task.isSuccessful()) {
final String token = task.getResult().getToken();
Logger.d("Registering push notifications token: " + token);
pinpointManager.getNotificationClient().registerDeviceToken(token);
} else {
Logger.e("onComplete(): Failed: " + task.getException().getMessage());
}
}
});
}
return pinpointManager;
}
use of com.google.firebase.iid.InstanceIdResult in project IITB-App by wncc.
the class LoginActivity method onStart.
@Override
protected void onStart() {
super.onStart();
// Initialize
ServiceGenerator serviceGenerator = new ServiceGenerator(getApplicationContext());
this.retrofitInterface = serviceGenerator.getRetrofitInterface();
// Get FCM Id
FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(new OnSuccessListener<InstanceIdResult>() {
@Override
public void onSuccess(InstanceIdResult instanceIdResult) {
fcmId = instanceIdResult.getToken();
}
});
// Login if intent is present
String action = getIntent().getAction();
String data = getIntent().getDataString();
if (Intent.ACTION_VIEW.equals(action) && data != null) {
Uri query = Uri.parse(data);
authCode = query.getQueryParameter("code");
if (authCode != null) {
/* Show progress dialog */
progressDialog.setMessage("Logging In");
progressDialog.setCancelable(false);
progressDialog.setIndeterminate(true);
if (!progressDialog.isShowing()) {
progressDialog.show();
}
/* Perform the login */
login(authCode, redirectUri);
} else {
Toast.makeText(this, "Login Failed!", Toast.LENGTH_SHORT).show();
}
}
// Setup web view placeholder
WebView webview = findViewById(R.id.login_webview);
webview.setWebViewClient(new WvClient());
webview.loadUrl("file:///android_asset/login.html");
}
use of com.google.firebase.iid.InstanceIdResult in project IITB-App by wncc.
the class MainActivity method updateFCMId.
/**
* Update FCM Id and update profile
*/
private void updateFCMId() {
FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(new OnSuccessListener<InstanceIdResult>() {
@Override
public void onSuccess(InstanceIdResult instanceIdResult) {
final String fcmId = instanceIdResult.getToken();
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.patchUserMe(Utils.getSessionIDHeader(), new UserFCMPatchRequest(fcmId, getCurrentVersion())).enqueue(new EmptyCallback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
if (response.isSuccessful()) {
session.createLoginSession(response.body().getUserName(), response.body(), session.getSessionID());
currentUser = response.body();
Utils.currentUserCache = currentUser;
} else {
session.logout();
currentUser = null;
Toast.makeText(MainActivity.this, "Your session has expired!", Toast.LENGTH_LONG).show();
}
}
});
}
});
}
use of com.google.firebase.iid.InstanceIdResult in project Android-SDK by Backendless.
the class FCMRegistration method registerDevice.
public static void registerDevice(final Context appContext, final List<String> channels, final long expiration, final AsyncCallback<DeviceRegistrationResult> callback) {
FCMRegistration.checkConfiguration(appContext);
FirebaseMessaging.getInstance().subscribeToTopic(DEFAULT_TOPIC).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (!task.isSuccessful()) {
Log.e(TAG, "Failed to subscribe in FCM.", task.getException());
if (callback != null)
callback.handleFault(new BackendlessFault("Failed to subscribe in FCM. " + task.getException().getMessage()));
} else
FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
@Override
public void onComplete(@NonNull Task<InstanceIdResult> task) {
if (!task.isSuccessful()) {
Log.e(TAG, "Can not retrieve deviceToken from FCM.", task.getException());
if (callback != null)
callback.handleFault(new BackendlessFault("Can not retrieve deviceToken from FCM. " + task.getException().getMessage()));
} else {
String deviceToken = task.getResult().getToken();
DeviceRegistrationResult devRegResult = (callback != null) ? new DeviceRegistrationResult().setDeviceToken(deviceToken) : null;
FCMRegistration.registerOnBackendless(appContext, deviceToken, channels, expiration, callback, devRegResult);
}
}
});
}
});
}
Aggregations