Java Code Examples for com.polidea.rxandroidble2.exceptions.BleScanException#getReason()

The following examples show how to use com.polidea.rxandroidble2.exceptions.BleScanException#getReason() . 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: ScanExceptionHandler.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
/**
 * Show toast with error message appropriate to exception reason.
 *
 * @param context   current Activity context
 * @param exception BleScanException to show error message for
 */
public static void handleException(final Activity context, final BleScanException exception) {
    final String text;
    final int reason = exception.getReason();

    // Special case, as there might or might not be a retry date suggestion
    if (reason == BleScanException.UNDOCUMENTED_SCAN_THROTTLE) {
        text = getUndocumentedScanThrottleErrorMessage(context, exception.getRetryDateSuggestion());
    } else {
        // Handle all other possible errors
        final Integer resId = ERROR_MESSAGES.get(reason);
        if (resId != null) {
            text = context.getString(resId);
        } else {
            // unknown error - return default message
            Log.w("Scanning", String.format("No message found for reason=%d. Consider adding one.", reason));
            text = context.getString(R.string.error_unknown_error);
        }
    }

    Log.w("Scanning", text, exception);
    Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
}