Search in sources :

Example 1 with InstanceIdResult

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();
    }
}
Also used : Intent(android.content.Intent) ExecutionException(java.util.concurrent.ExecutionException) InstanceIdResult(com.google.firebase.iid.InstanceIdResult)

Example 2 with InstanceIdResult

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;
}
Also used : PinpointConfiguration(com.amazonaws.mobileconnectors.pinpoint.PinpointConfiguration) PinpointManager(com.amazonaws.mobileconnectors.pinpoint.PinpointManager) InstanceIdResult(com.google.firebase.iid.InstanceIdResult)

Example 3 with InstanceIdResult

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");
}
Also used : ServiceGenerator(app.insti.api.ServiceGenerator) WebView(android.webkit.WebView) Uri(android.net.Uri) InstanceIdResult(com.google.firebase.iid.InstanceIdResult)

Example 4 with InstanceIdResult

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();
                    }
                }
            });
        }
    });
}
Also used : Response(retrofit2.Response) Call(retrofit2.Call) EmptyCallback(app.insti.api.EmptyCallback) InstanceIdResult(com.google.firebase.iid.InstanceIdResult) RetrofitInterface(app.insti.api.RetrofitInterface) UserFCMPatchRequest(app.insti.api.request.UserFCMPatchRequest)

Example 5 with InstanceIdResult

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);
                        }
                    }
                });
        }
    });
}
Also used : InstanceIdResult(com.google.firebase.iid.InstanceIdResult) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Aggregations

InstanceIdResult (com.google.firebase.iid.InstanceIdResult)5 Intent (android.content.Intent)1 Uri (android.net.Uri)1 WebView (android.webkit.WebView)1 EmptyCallback (app.insti.api.EmptyCallback)1 RetrofitInterface (app.insti.api.RetrofitInterface)1 ServiceGenerator (app.insti.api.ServiceGenerator)1 UserFCMPatchRequest (app.insti.api.request.UserFCMPatchRequest)1 PinpointConfiguration (com.amazonaws.mobileconnectors.pinpoint.PinpointConfiguration)1 PinpointManager (com.amazonaws.mobileconnectors.pinpoint.PinpointManager)1 BackendlessFault (com.backendless.exceptions.BackendlessFault)1 ExecutionException (java.util.concurrent.ExecutionException)1 Call (retrofit2.Call)1 Response (retrofit2.Response)1