title: Android: Sms Retrieval Api does not get message from intent
body: <p>I tried to implement the new Sms retrieval Api in my android application but I could not read the message correctly, my service gets called when a message is received but I cannot get the content of the message from the intent's extras. Here is a sample code from my service:</p>
  
  <pre><code>/**
   * BroadcastReceiver to wait for SMS messages. This can be registered either
   * in the AndroidManifest or at runtime.  Should filter Intents on
   * SmsRetriever.SMS_RETRIEVED_ACTION.
   */
  public class SmsVerificationReceiver extends BroadcastReceiver {
  
  @Override
  public void onReceive(Context context, Intent intent) {
      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:
                  // Get SMS message contents
                  String message = (String) extras.get(SmsRetriever.EXTRA_SMS_MESSAGE);
                  Timber.d(message);
                  Toast.makeText(context, "Message is: "+ message, Toast.LENGTH_LONG).show();
                  // Extract one-time code from the message and complete verification
                  // by sending the code back to your server.
                  break;
              case CommonStatusCodes.TIMEOUT:
                  // Waiting for SMS timed out (5 minutes)
                  // Handle the error ...
                  break;
          }
      }
    }
  }
  </code></pre>
  
  <p>Also here is the code sample for how I get the 11 digit token for my application signature, </p>
  
  <pre><code>/**
       * This is a helper class to generate your message hash to be included in your SMS message.
       *
       * Without the correct hash, your app won't recieve the message callback. This only needs to be
       * generated once per app and stored. Then you can remove this helper class from your code.
       */
      public class AppSignatureHelper extends ContextWrapper {
          public static final String TAG = AppSignatureHelper.class.getSimpleName();
      private static final String HASH_TYPE = "SHA-256";
      public static final int NUM_HASHED_BYTES = 9;
      public static final int NUM_BASE64_CHAR = 11;
  
      public AppSignatureHelper(Context context) {
          super(context);
      }
  
  /**
   * Get all the app signatures for the current package
   * @return
   */
  @RequiresApi(api = Build.VERSION_CODES.KITKAT)
  public ArrayList&lt;String&gt; getAppSignatures() {
      ArrayList&lt;String&gt; appCodes = new ArrayList&lt;&gt;();
  
      try {
          // Get all package signatures for the current package
          String packageName = getPackageName();
          PackageManager packageManager = getPackageManager();
          Signature[] signatures = packageManager.getPackageInfo(packageName,
                  PackageManager.GET_SIGNATURES).signatures;
  
          // For each signature create a compatible hash
          for (Signature signature : signatures) {
              String hash = hash(packageName, signature.toCharsString());
              if (hash != null) {
                  appCodes.add(String.format("%s", hash));
              }
          }
      } catch (PackageManager.NameNotFoundException e) {
          Log.e(TAG, "Unable to find package to obtain hash.", e);
      }
      Toast.makeText(this, "App code is: " + appCodes.toString(), Toast.LENGTH_LONG).show();
      ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
      ClipData clip = ClipData.newPlainText("App has Key", appCodes.toString());
      clipboard.setPrimaryClip(clip);
      return appCodes;
  }
  
  @RequiresApi(api = Build.VERSION_CODES.KITKAT)
  private  String hash(String packageName, String signature) {
      String appInfo = packageName + " " + signature;
      try {
          MessageDigest messageDigest = MessageDigest.getInstance(HASH_TYPE);
          messageDigest.update(appInfo.getBytes(StandardCharsets.UTF_8));
          byte[] hashSignature = messageDigest.digest();
  
          // truncated into NUM_HASHED_BYTES
          hashSignature = Arrays.copyOfRange(hashSignature, 0, NUM_HASHED_BYTES);
          // encode into Base64
          String base64Hash = Base64.encodeToString(hashSignature, Base64.NO_PADDING | Base64.NO_WRAP);
          base64Hash = base64Hash.substring(0, NUM_BASE64_CHAR);
  
          Toast.makeText(this, "PKG IS is: " + base64Hash, Toast.LENGTH_LONG).show();
          Log.d(TAG, String.format("pkg: %s -- hash: %s", packageName, base64Hash));
          return base64Hash;
      } catch (NoSuchAlgorithmException e) {
          Log.e(TAG, "hash:NoSuchAlgorithm", e);
      }
      return null;
  }
  }
  </code></pre>
  
  <p>In the service, this line </p>
  
  <pre><code> String message = (String) extras.get(SmsRetriever.EXTRA_SMS_MESSAGE);
  </code></pre>
  
  <p>always return null.</p>
  
  <p>Also, this is the sample of the SMS I sent (less than 140 bytes)</p>
  
  <p><code>[#] his this is your code: 1234 APP_11_DIGIT_SIGNATURE</code></p>