huawei-mobile-serviceshuawei-developershuawei-account

Huawei Account Kit Automatic phone verification is not working


I have been trying to make the automatic phone verification work, but it does not fill the verification.

public class MySMSBroadcastReceiver extends BroadcastReceiver { 



@Override public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();

 if (bundle != null)

 { Status status = bundle.getParcelable(ReadSmsConstant.EXTRA_STATUS); if (status.getStatusCode() == CommonStatusCodes.TIMEOUT) { // Service has timed out and no SMS message that meets the requirement is read. Service ended. doSomethingWhenTimeOut(); } 

else if (status.getStatusCode() == CommonStatusCodes.SUCCESS) { 

if (bundle.containsKey(ReadSmsConstant.EXTRA_SMS_MESSAGE)) { 

// An SMS message that meets the requirement is read. Service ended. doSomethingWhenGetMessage(bundle.getString(ReadSmsConstant.EXTRA_SMS_MESSAGE)); } } } } }

Solution

  • We need to also have a completion callback to catch the message to do action:

    Task<Void> task = ReadSmsManager.start(MainActivity.this);
    task.addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(Task<Void> task) {
            if (task.isSuccessful()) {
                // The service is enabled successfully. Continue with the process.
                doSomethingWhenTaskSuccess();
            }
        }
    });