华为帐户工具包自动电话验证不起作用

问题描述

我一直在尝试让自动电话验证工作,但它没有填写验证。

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)); } } } } }

解决方法

我们还需要一个完成回调来捕捉消息以执行操作:

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();
        }
    }
});

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...