Java Code Examples for com.google.android.gms.common.api.CommonStatusCodes#SUCCESS

The following examples show how to use com.google.android.gms.common.api.CommonStatusCodes#SUCCESS . 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: FlutterBarcodeScannerPlugin.java    From flutter_barcode_scanner with MIT License 6 votes vote down vote up
/**
 * Get the barcode scanning results in onActivityResult
 *
 * @param requestCode
 * @param resultCode
 * @param data
 * @return
 */
@Override
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == RC_BARCODE_CAPTURE) {
        if (resultCode == CommonStatusCodes.SUCCESS) {
            if (data != null) {
                try {
                    Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject);
                    String barcodeResult = barcode.rawValue;
                    pendingResult.success(barcodeResult);
                } catch (Exception e) {
                    pendingResult.success("-1");
                }
            } else {
                pendingResult.success("-1");
            }
            pendingResult = null;
            arguments = null;
            return true;
        } else {
            pendingResult.success("-1");
        }
    }
    return false;
}
 
Example 3
Source File: MainActivity.java    From android-vision with Apache License 2.0 6 votes vote down vote up
/**
 * Called when an activity you launched exits, giving you the requestCode
 * you started it with, the resultCode it returned, and any additional
 * data from it.  The <var>resultCode</var> will be
 * {@link #RESULT_CANCELED} if the activity explicitly returned that,
 * didn't return any result, or crashed during its operation.
 * <p/>
 * <p>You will receive this call immediately before onResume() when your
 * activity is re-starting.
 * <p/>
 *
 * @param requestCode The integer request code originally supplied to
 *                    startActivityForResult(), allowing you to identify who this
 *                    result came from.
 * @param resultCode  The integer result code returned by the child activity
 *                    through its setResult().
 * @param data        An Intent, which can return result data to the caller
 *                    (various data can be attached to Intent "extras").
 * @see #startActivityForResult
 * @see #createPendingResult
 * @see #setResult(int)
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode == RC_OCR_CAPTURE) {
        if (resultCode == CommonStatusCodes.SUCCESS) {
            if (data != null) {
                String text = data.getStringExtra(OcrCaptureActivity.TextBlockObject);
                statusMessage.setText(R.string.ocr_success);
                textValue.setText(text);
                Log.d(TAG, "Text read: " + text);
            } else {
                statusMessage.setText(R.string.ocr_failure);
                Log.d(TAG, "No Text captured, intent data is null");
            }
        } else {
            statusMessage.setText(String.format(getString(R.string.ocr_error),
                    CommonStatusCodes.getStatusCodeString(resultCode)));
        }
    }
    else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
 
Example 4
Source File: MainActivity.java    From android-vision with Apache License 2.0 6 votes vote down vote up
/**
 * Called when an activity you launched exits, giving you the requestCode
 * you started it with, the resultCode it returned, and any additional
 * data from it.  The <var>resultCode</var> will be
 * {@link #RESULT_CANCELED} if the activity explicitly returned that,
 * didn't return any result, or crashed during its operation.
 * <p/>
 * <p>You will receive this call immediately before onResume() when your
 * activity is re-starting.
 * <p/>
 *
 * @param requestCode The integer request code originally supplied to
 *                    startActivityForResult(), allowing you to identify who this
 *                    result came from.
 * @param resultCode  The integer result code returned by the child activity
 *                    through its setResult().
 * @param data        An Intent, which can return result data to the caller
 *                    (various data can be attached to Intent "extras").
 * @see #startActivityForResult
 * @see #createPendingResult
 * @see #setResult(int)
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == RC_BARCODE_CAPTURE) {
        if (resultCode == CommonStatusCodes.SUCCESS) {
            if (data != null) {
                Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject);
                statusMessage.setText(R.string.barcode_success);
                barcodeValue.setText(barcode.displayValue);
                Log.d(TAG, "Barcode read: " + barcode.displayValue);
            } else {
                statusMessage.setText(R.string.barcode_failure);
                Log.d(TAG, "No barcode captured, intent data is null");
            }
        } else {
            statusMessage.setText(String.format(getString(R.string.barcode_error),
                    CommonStatusCodes.getStatusCodeString(resultCode)));
        }
    }
    else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
 
Example 5
Source File: MainActivity.java    From Questor with MIT License 6 votes vote down vote up
/**
 * Called when an activity you launched exits, giving you the requestCode
 * you started it with, the resultCode it returned, and any additional
 * data from it.  The <var>resultCode</var> will be
 * {@link #RESULT_CANCELED} if the activity explicitly returned that,
 * didn't return any result, or crashed during its operation.
 * <p/>
 * <p>You will receive this call immediately before onResume() when your
 * activity is re-starting.
 * <p/>
 *
 * @param requestCode The integer request code originally supplied to
 *                    startActivityForResult(), allowing you to identify who this
 *                    result came from.
 * @param resultCode  The integer result code returned by the child activity
 *                    through its setResult().
 * @param data        An Intent, which can return result data to the caller
 *                    (various data can be attached to Intent "extras").
 * @see #startActivityForResult
 * @see #createPendingResult
 * @see #setResult(int)
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode == RC_OCR_CAPTURE) {
        if (resultCode == CommonStatusCodes.SUCCESS) {
            if (data != null) {
                String text = data.getStringExtra(OcrCaptureActivity.TextBlockObject);
                statusMessage.setText(R.string.ocr_success);
                textValue.setText(text);
                Log.d(TAG, "Text read: " + text);
            } else {
                statusMessage.setText(R.string.ocr_failure);
                Log.d(TAG, "No Text captured, intent data is null");
            }
        } else {
            statusMessage.setText(String.format(getString(R.string.ocr_error),
                    CommonStatusCodes.getStatusCodeString(resultCode)));
        }
        displayStatus();
    }
    else {
        super.onActivityResult(requestCode, resultCode, data);


 }
}
 
Example 6
Source File: MainActivity.java    From OCR-Reader with MIT License 6 votes vote down vote up
/**
 * Called when an activity you launched exits, giving you the requestCode
 * you started it with, the resultCode it returned, and any additional
 * data from it.  The <var>resultCode</var> will be
 * {@link #RESULT_CANCELED} if the activity explicitly returned that,
 * didn't return any result, or crashed during its operation.
 * <p/>
 * <p>You will receive this call immediately before onResume() when your
 * activity is re-starting.
 * <p/>
 *
 * @param requestCode The integer request code originally supplied to
 *                    startActivityForResult(), allowing you to identify who this
 *                    result came from.
 * @param resultCode  The integer result code returned by the child activity
 *                    through its setResult().
 * @param data        An Intent, which can return result data to the caller
 *                    (various data can be attached to Intent "extras").
 * @see #startActivityForResult
 * @see #createPendingResult
 * @see #setResult(int)
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode == RC_OCR_CAPTURE) {
        if (resultCode == CommonStatusCodes.SUCCESS) {
            if (data != null) {
                String text = data.getStringExtra(OcrCaptureActivity.TextBlockObject);
                statusMessage.setText(R.string.ocr_success);
                textValue.setText(text);
                Log.d(TAG, "Text read: " + text);
            } else {
                statusMessage.setText(R.string.ocr_failure);
                Log.d(TAG, "No Text captured, intent data is null");
            }
        } else {
            statusMessage.setText(String.format(getString(R.string.ocr_error),
                    CommonStatusCodes.getStatusCodeString(resultCode)));
        }
    }
    else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
 
Example 7
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 8
Source File: SendActivity.java    From trust-wallet-android-source with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == BARCODE_READER_REQUEST_CODE) {
        if (resultCode == CommonStatusCodes.SUCCESS) {
            if (data != null) {
                Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject);

                QRURLParser parser = QRURLParser.getInstance();
                String extracted_address = parser.extractAddressFromQrString(barcode.displayValue);
                if (extracted_address == null) {
                    Toast.makeText(this, R.string.toast_qr_code_no_address, Toast.LENGTH_SHORT).show();
                    return;
                }
                Point[] p = barcode.cornerPoints;
                toAddressText.setText(extracted_address);
            }
        } else {
            Log.e("SEND", String.format(getString(R.string.barcode_error_format),
                    CommonStatusCodes.getStatusCodeString(resultCode)));
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
 
Example 9
Source File: HomeFragment.java    From mobikul-standalone-pos with MIT License 6 votes vote down vote up
public void onActivityResult(final int requestCode, int resultCode, Intent intent) {
    if (requestCode == BARCODE_READER_REQUEST_CODE) {
        if (resultCode == CommonStatusCodes.SUCCESS) {
            if (intent != null) {
                Barcode barcode = intent.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject);
                Point[] p = barcode.cornerPoints;

                DataBaseController.getInstanse().getProductByBarcode(getActivity(), barcode.displayValue, new DataBaseCallBack() {
                    @Override
                    public void onSuccess(Object responseData, String successMsg) {
                        binding.getHandler().onClickProduct((Product) responseData);
                    }

                    @Override
                    public void onFailure(int errorCode, String errorMsg) {

                    }
                });

            } else
                ToastHelper.showToast(getActivity(), "No code found!!", Toast.LENGTH_SHORT);
        } else
            Log.e(TAG, String.format(getString(R.string.barcode_error_format),
                    CommonStatusCodes.getStatusCodeString(resultCode)));
    }
}
 
Example 10
Source File: MainActivity.java    From QuickerAndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);


        if (requestCode == REQ_CODE_SCAN_BRCODE) {
            if (resultCode == CommonStatusCodes.SUCCESS) {
                String qrcode = data.getStringExtra("barcode");
                Log.d(TAG, "扫描结果:" + qrcode);

                clientService.getClientManager().sendTextMsg(TextDataMessage.TYPE_QRCODE, qrcode);


            }
        } else if (requestCode == VOICE_RECOGNITION_REQUEST_CODE) {
            if (resultCode == RESULT_OK && data != null) {
                //返回结果是一个list,我们一般取的是第一个最匹配的结果
                ArrayList<String> text = data
                        .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);


                clientService.getClientManager().sendTextMsg(TextDataMessage.TYPE_VOICE_RECOGNITION, text.get(0));
            }
        } else if (requestCode == REQUEST_TAKE_PHOTO) {
            if (resultCode == RESULT_OK) {
                // readPic();

                Bitmap bitmap = ImagePicker.getImageFromResult(this, resultCode, data);
                sendImage(bitmap);
            } else {
//                    Bitmap bitmap=MediaStore.Images.Media.getBitmap(getContentResolver(),imageUri);
//                    iv_image.setImageBitmap(bitmap);
            }
        }


    }
 
Example 11
Source File: MainActivity.java    From samples-android with Apache License 2.0 5 votes vote down vote up
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == RESULT_CODE) {
        if(data.getBooleanExtra(RESULT_KEY, false)) {
            updateTokens();
        }
    } else if(requestCode == BARCODE_RESULT_CODE) {
        if(resultCode == CommonStatusCodes.SUCCESS) {
            if (data != null) {
                Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject);
                addTokenFormBarcodeScanner(barcode);
            }
        }
    }
}
 
Example 12
Source File: AddAndEditSpendingFragment.java    From Moneycim with MIT License 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode == RC_OCR_CAPTURE) {
        if (resultCode == CommonStatusCodes.SUCCESS) {
            if (data != null) {
                String text = data.getStringExtra(OcrCaptureActivity.TextBlockObject);
                text = trimQuantity(text);
                quantityEditText.setText(text);
            }
        } else {
            showSnackBar("Error");
        }
    }
}
 
Example 13
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 14
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 15
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 16
Source File: CapabilityManager.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
public int add(String capability) {
    if (this.capabilities.contains(capability)) {
        return WearableStatusCodes.DUPLICATE_CAPABILITY;
    }
    DataItemInternal dataItem = new DataItemInternal(buildCapabilityUri(capability, true));
    DataItemRecord record = wearable.putDataItem(packageName, PackageUtils.firstSignatureDigest(context, packageName), wearable.getLocalNodeId(), dataItem);
    this.capabilities.add(capability);
    wearable.syncRecordToAll(record);
    return CommonStatusCodes.SUCCESS;
}
 
Example 17
Source File: CapabilityManager.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
public int remove(String capability) {
    if (!this.capabilities.contains(capability)) {
        return WearableStatusCodes.UNKNOWN_CAPABILITY;
    }
    wearable.deleteDataItems(buildCapabilityUri(capability, true), packageName);
    capabilities.remove(capability);
    return CommonStatusCodes.SUCCESS;
}
 
Example 18
Source File: RxStatus.java    From RxSocialAuth with Apache License 2.0 4 votes vote down vote up
public RxStatus(int statusCode, String message) {
    this.statusCode = statusCode;
    this.message = message;
    this.success = statusCode == CommonStatusCodes.SUCCESS;
}