content: package de.androidcrypto.android_hce_beginner_app;
  
  import static android.content.Context.VIBRATOR_SERVICE;
  
  import android.app.Activity;
  import android.os.Build;
  import android.os.VibrationEffect;
  import android.os.Vibrator;
  
  public class Utils {
  
      public static String bytesToHexNpe(byte[] bytes) {
          if (bytes == null) return "";
          StringBuffer result = new StringBuffer();
          for (byte b : bytes)
              result.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1));
          return result.toString();
      }
  
      public static byte[] hexStringToByteArray(String s) {
          int len = s.length();
          byte[] data = new byte[len / 2];
          for (int i = 0; i < len; i += 2) {
              data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
                      + Character.digit(s.charAt(i + 1), 16));
          }
          return data;
      }
  
      public static void doVibrate(Activity activity) {
          if (activity != null) {
              // Make a Sound
              if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                  ((Vibrator) activity.getSystemService(VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(50, 10));
              } else {
                  Vibrator v = (Vibrator) activity.getSystemService(VIBRATOR_SERVICE);
                  v.vibrate(50);
              }
          }
      }
  
  }
  