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 ( ) ; }
Show toast with error message appropriate to exception reason .