Java Code Examples for com.google.android.gms.common.api.Status#getStatusCode()

The following examples show how to use com.google.android.gms.common.api.Status#getStatusCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegistrationNavigationActivity.java    From mollyim-android with GNU General Public License v3.0 7 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
  Log.i(TAG, "SmsRetrieverReceiver received a broadcast...");

  if (SmsRetriever.SMS_RETRIEVED_ACTION.equals(intent.getAction())) {
    Bundle extras = intent.getExtras();
    Status status = (Status) extras.get(SmsRetriever.EXTRA_STATUS);

    switch (status.getStatusCode()) {
      case CommonStatusCodes.SUCCESS:
        Optional<String> code = VerificationCodeParser.parse(context, (String) extras.get(SmsRetriever.EXTRA_SMS_MESSAGE));
        if (code.isPresent()) {
          Log.i(TAG, "Received verification code.");
          handleVerificationCodeReceived(code.get());
        } else {
          Log.w(TAG, "Could not parse verification code.");
        }
        break;
      case CommonStatusCodes.TIMEOUT:
        Log.w(TAG, "Hit a timeout waiting for the SMS to arrive.");
        break;
    }
  } else {
    Log.w(TAG, "SmsRetrieverReceiver received the wrong action?");
  }
}
 
Example 2
Source File: OtpBroadcastReceiver.java    From react-native-otp-verify with MIT License 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String o = intent.getAction();
    if (SmsRetriever.SMS_RETRIEVED_ACTION.equals(o)) {
        Bundle extras = intent.getExtras();
        Status status = (Status) extras.get(SmsRetriever.EXTRA_STATUS);

        switch (status.getStatusCode()) {
            case CommonStatusCodes.SUCCESS:
                // Get SMS message contents
                String message = (String) extras.get(SmsRetriever.EXTRA_SMS_MESSAGE);
                receiveMessage(message);
                Log.d("SMS", message);
                break;
            case CommonStatusCodes.TIMEOUT:
                Log.d("SMS", "Timeout error");
                mContext
                        .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                        .emit(EVENT, "Timeout Error.");
                break;
        }
    }
}
 
Example 3
Source File: LocationSwitch.java    From react-native-location-switch with Apache License 2.0 6 votes vote down vote up
@Override
public void onResult(LocationSettingsResult result) {
    final Status status = result.getStatus();
    switch (status.getStatusCode()) {
        case LocationSettingsStatusCodes.SUCCESS:
            // All location settings are satisfied -> nothing to do
            callSuccessCallback();
            break;
        case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
            // Location settings are not satisfied. Show the user a dialog to upgrade location settings
            try {
                // Show the dialog by calling startResolutionForResult(), and check the result
                status.startResolutionForResult(mActivity, REQUEST_CHECK_SETTINGS);
            } catch (IntentSender.SendIntentException e) {
                Log.e(TAG, "PendingIntent unable to execute request.", e);
                callErrorCallback();
            }
            break;
        case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
            Log.e(TAG, "Location settings are inadequate, and cannot be fixed here. Dialog not created.");
            callErrorCallback();
            break;
    }
}
 
Example 4
Source File: RxSmartLockPasswordsFragment.java    From RxSocialAuth with Apache License 2.0 6 votes vote down vote up
private void resolveResult(Status status) {
    if (status.getStatusCode() == CommonStatusCodes.RESOLUTION_REQUIRED) {
        try {
            //status.startResolutionForResult(mActivity, RC_READ);
            startIntentSenderForResult(status.getResolution().getIntentSender(), RC_READ, null, 0, 0, 0, null);
        } catch (IntentSender.SendIntentException e) {
            e.printStackTrace();
            mCredentialsApiClient.disconnect();
            mAccountSubject.onError(new Throwable(e.toString()));
        }
    }
    else {
        // The user must create an account or sign in manually.
        mCredentialsApiClient.disconnect();
        mAccountSubject.onError(new Throwable(getString(R.string.status_canceled_request_credential)));
    }
}
 
Example 5
Source File: TimeAttendantFastFragment.java    From iBeacon-Android with Apache License 2.0 6 votes vote down vote up
@Override
public void onResult(@NonNull LocationSettingsResult locationSettingsResult) {
    final Status status = locationSettingsResult.getStatus();
    switch (status.getStatusCode()) {
        case LocationSettingsStatusCodes.SUCCESS:
            Log.i(TAG, "All location settings are satisfied.");
            break;
        case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
            Log.i(TAG, "Location settings are not satisfied. Show the user a dialog to upgrade location settings ");

            try {
                // Show the dialog by calling startResolutionForResult(), and check the result
                // in onActivityResult().
                status.startResolutionForResult(getActivity(), REQUEST_CHECK_SETTINGS);
            } catch (IntentSender.SendIntentException e) {
                Log.i(TAG, "PendingIntent unable to execute request.");
            }
            break;
        case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
            Log.i(TAG, "Location settings are inadequate, and cannot be fixed here. Dialog not created.");
            break;
    }
}
 
Example 6
Source File: BeaconsFragment.java    From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void handleUnsuccessfulNearbyResult(Status status) {
    Log.v(TAG, "Processing error, status = " + status);
    if (mResolvingError) {
        // Already attempting to resolve an error.
        return;
    } else if (status.hasResolution()) {
        try {
            mResolvingError = true;
            status.startResolutionForResult(getActivity(),
                    REQUEST_RESOLVE_ERROR);
        } catch (IntentSender.SendIntentException e) {
            mResolvingError = false;
            Log.v(TAG, "Failed to resolve error status.", e);
        }
    } else {
        if (status.getStatusCode() == CommonStatusCodes.NETWORK_ERROR) {
            Toast.makeText(getActivity(),
                    "No connectivity, cannot proceed. Fix in 'Settings' and try again.",
                    Toast.LENGTH_LONG).show();
        } else {
            // To keep things simple, pop a toast for all other error messages.
            Toast.makeText(getActivity(), "Unsuccessful: " +
                    status.getStatusMessage(), Toast.LENGTH_LONG).show();
        }
    }
}
 
Example 7
Source File: MainActivity.java    From journaldev with MIT License 6 votes vote down vote up
@Override
public void onResult(@NonNull CredentialRequestResult credentialRequestResult) {

    Status status = credentialRequestResult.getStatus();
    if (status.isSuccess()) {
        onCredentialRetrieved(credentialRequestResult.getCredential());
    } else {
        if (status.getStatusCode() == CommonStatusCodes.RESOLUTION_REQUIRED) {
            try {
                isResolving = true;
                status.startResolutionForResult(this, RC_READ);
            } catch (IntentSender.SendIntentException e) {
                Log.d(TAG, e.toString());
            }
        } else {

            showHintDialog();
        }
    }
}
 
Example 8
Source File: PhoneNumberVerifier.java    From identity-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (intent == null) {
        return;
    }

    String action = intent.getAction();
    if (SmsRetriever.SMS_RETRIEVED_ACTION.equals(action)) {
        cancelTimeout();
        notifyStatus(STATUS_RESPONSE_RECEIVED, null);
        Bundle extras = intent.getExtras();
        Status status = (Status) extras.get(SmsRetriever.EXTRA_STATUS);
        switch(status.getStatusCode()) {
            case CommonStatusCodes.SUCCESS:
                String smsMessage = (String) extras.get(SmsRetriever.EXTRA_SMS_MESSAGE);
                Log.d(TAG, "Retrieved sms code: " + smsMessage);
                if (smsMessage != null) {
                    verifyMessage(smsMessage);
                }
                break;
            case CommonStatusCodes.TIMEOUT:
                doTimeout();
                break;
            default:
                break;
        }
    }
}
 
Example 9
Source File: SmsBroadcastReceiver.java    From react-native-sms-retriever with MIT License 5 votes vote down vote up
@Override
public void onReceive(final Context context, final Intent intent) {
    if (SmsRetriever.SMS_RETRIEVED_ACTION.equals(intent.getAction())) {
        final Bundle extras = intent.getExtras();
        if (extras == null) {
            emitJSEvent(EXTRAS_KEY, EXTRAS_NULL_ERROR_MESSAGE);
            return;
        }

        final Status status = (Status) extras.get(SmsRetriever.EXTRA_STATUS);
        if (status == null) {
            emitJSEvent(STATUS_KEY, STATUS_NULL_ERROR_MESSAGE);
            return;
        }

        switch (status.getStatusCode()) {
            case CommonStatusCodes.SUCCESS: {
                final String message = (String) extras.get(SmsRetriever.EXTRA_SMS_MESSAGE);
                emitJSEvent(MESSAGE_KEY, message);
                break;
            }

            case CommonStatusCodes.TIMEOUT: {
                emitJSEvent(TIMEOUT_KEY, TIMEOUT_ERROR_MESSAGE);
                break;
            }
        }
    }
}
 
Example 10
Source File: MessageFragment.java    From io16experiment-master with Apache License 2.0 5 votes vote down vote up
/**
 * Handles errors generated when performing a subscription or publication action. Uses
 * {@link Status#startResolutionForResult} to display an opt-in dialog to handle the case
 * where a device is not opted into using Nearby.
 */
private void handleUnsuccessfulNearbyResult(Status status) {
    LogUtils.LOGE(TAG, "processing error, status = " + status);
    if (status.getStatusCode() == NearbyMessagesStatusCodes.APP_NOT_OPTED_IN) {
        if (!mResolvingNearbyPermissionError) {
            try {
                mResolvingNearbyPermissionError = true;
                status.startResolutionForResult(mActivity, Constants.REQUEST_RESOLVE_ERROR);

            } catch (IntentSender.SendIntentException e) {
                e.printStackTrace();
            }
        }
    } else {
        if (status.getStatusCode() == ConnectionResult.NETWORK_ERROR) {
            Toast.makeText(mActivity.getApplicationContext(),
                    "No connectivity, cannot proceed. Fix in 'Settings' and try again.",
                    Toast.LENGTH_LONG).show();
            resetToDefaultState();
        } else {
            // To keep things simple, pop a toast for all other error messages.
            Toast.makeText(mActivity.getApplicationContext(), "Unsuccessful: " +
                    status.getStatusMessage(), Toast.LENGTH_LONG).show();
        }

    }
}
 
Example 11
Source File: PhoneNumberVerifier.java    From android-credentials with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (intent == null) {
        return;
    }

    String action = intent.getAction();
    if (SmsRetriever.SMS_RETRIEVED_ACTION.equals(action)) {
        cancelTimeout();
        notifyStatus(STATUS_RESPONSE_RECEIVED, null);
        Bundle extras = intent.getExtras();
        Status status = (Status) extras.get(SmsRetriever.EXTRA_STATUS);
        switch(status.getStatusCode()) {
            case CommonStatusCodes.SUCCESS:
                String smsMessage = (String) extras.get(SmsRetriever.EXTRA_SMS_MESSAGE);
                Log.d(TAG, "Retrieved sms code: " + smsMessage);
                if (smsMessage != null) {
                    verifyMessage(smsMessage);
                }
                break;
            case CommonStatusCodes.TIMEOUT:
                doTimeout();
                break;
            default:
                break;
        }
    }
}
 
Example 12
Source File: FitResultCallback.java    From android-play-games-in-motion with Apache License 2.0 5 votes vote down vote up
private void onRecordingSubscription(Status status) {
    if (status.isSuccess()) {
        if (status.getStatusCode()
                == FitnessStatusCodes.SUCCESS_ALREADY_SUBSCRIBED) {
            Utils.logDebug(TAG, "Existing subscription for activity detected.");
        } else {
            Utils.logDebug(TAG, "Started recording data for " + mDataType);
        }
    } else {
        // For a better user experience, you can add visual error text indicating the session
        // will not be recorded to the cloud.
        Utils.logDebug(TAG, "Unable to start recording data for " + mDataType);
    }
}
 
Example 13
Source File: RxStatus.java    From RxSocialAuth with Apache License 2.0 4 votes vote down vote up
public RxStatus(Status status) {
    this.statusCode = status.getStatusCode();
    this.message = status.getStatusMessage();
    this.success = status.isSuccess();
}
 
Example 14
Source File: LocationAvailableAsyncEmitter.java    From Forage with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void call(AsyncEmitter<Void> locationAsyncEmitter) {

    GoogleApiClient.OnConnectionFailedListener onConnectionFailedListener = connectionResult ->
            locationAsyncEmitter.onError(new LocationUnavailableException("Failed to connect to Google Play Services!"));

    ResultCallback<LocationSettingsResult> pendingResultCallback = locationSettingsResult -> {
        Status status = locationSettingsResult.getStatus();
        if (status.getStatusCode() == LocationSettingsStatusCodes.SUCCESS) {
            locationAsyncEmitter.onCompleted();
        } else {
            locationAsyncEmitter.onError(new LocationUnavailableException("Location services not enabled!"));
        }
    };

    GoogleApiClient.ConnectionCallbacks connectionCallbacks = new GoogleApiClient.ConnectionCallbacks() {
        @Override
        public void onConnected(@Nullable Bundle bundle) {
            try {
                LocationRequest request = LocationRequest.create()
                        .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

                LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
                        .addLocationRequest(request)
                        .setAlwaysShow(true);

                PendingResult<LocationSettingsResult> result =
                        LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());

                result.setResultCallback(pendingResultCallback);

            } catch (SecurityException e) {
                locationAsyncEmitter.onError(new LocationUnavailableException("Location permission not available?"));
            }
        }

        @Override
        public void onConnectionSuspended(int i) {
            locationAsyncEmitter.onError(new LocationUnavailableException("Connection lost to Google Play Services"));

        }
    };

    googleApiClient.registerConnectionCallbacks(connectionCallbacks);
    googleApiClient.registerConnectionFailedListener(onConnectionFailedListener);
    googleApiClient.connect();

    locationAsyncEmitter.setCancellation(() -> {
        googleApiClient.unregisterConnectionCallbacks(connectionCallbacks);
        googleApiClient.unregisterConnectionFailedListener(onConnectionFailedListener);
    });
}