“sendVerificationCode” 方法在 Firebase 中未执行。

huangapple go评论63阅读模式
英文:

The "sendVerificationCode" method not excuting in firebase

问题

我在一个项目中工作,一切都正常。在编写代码时,我放置了“sendVerificationCode”方法并将其与一个按钮链接在一起,以便在点击按钮时执行,但当我点击按钮时它没有执行。

另外,我遇到了一个问题,即手机号的长度应该是10位。但是当我加入了条件语句后它没有起作用。

此外,日志中没有显示任何错误。

以下是代码部分:

        sPhoneNumber = findViewById(R.id.phoneNumberPrompt);
        Code = findViewById(R.id.codePrompt);
        mVerificationButton = findViewById(R.id.verificationButton);
        mSignButton = findViewById(R.id.signButton);

        mPhoneNumber = sPhoneNumber.getText().toString();
        mCode = Code.getText().toString();

        mVerificationButton.setOnClickListener(new View.OnClickListener()
        {

            @Override
            public void onClick(View view)
            {
                if (mPhoneNumber.length() != 10)
                {
                    sPhoneNumber.setError("请确保您的号码正确。");
                    sPhoneNumber.requestFocus();
                }
                else
                {
                    sendVerificationCode(mPhoneNumber);

                    sPhoneNumber.setError("成功工作");
                    sPhoneNumber.requestFocus();
                   // Log.d(Tag, mPhoneNumber);
                }
            }
        });

        mSignButton.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                verifyPhoneNumberWithCode(mVerificationId ,mCode);
            }
        });

    }

    private void verifyPhoneNumberWithCode(String verificationId, String aCode)
    {
        PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationId, aCode);
        signInWithPhoneAuthCredential(credential);
    }

    public void sendVerificationCode(String phoneNumber)
    {
        PhoneAuthProvider.getInstance().verifyPhoneNumber(
               "+49" + phoneNumber,        // 要验证的手机号码
                6,                 // 超时时长
                TimeUnit.SECONDS,   // 超时单位
                this,               // Activity(用于回调绑定)
                mCallbacks);        // OnVerificationStateChangedCallbacks
    }
英文:

I was working in a project every thing worked fine. while writing the code i put the "sendVerificationCode" metohd and linked it with a button so it could be excuted but it didnt excute when i clicked the button.

also i got this problem that the length of the Prompt phone number should be 10. but when i put the If statmernt it didnt work.

plus i dont get any errors in the log.

** Here is the code: **

        sPhoneNumber = findViewById(R.id.phoneNumberPrompt);
Code = findViewById(R.id.codePrompt);
mVerificationButton = findViewById(R.id.verificationButton);
mSignButton = findViewById(R.id.signButton);
mPhoneNumber = sPhoneNumber.getText().toString();
mCode = Code.getText().toString();
mVerificationButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
if (mPhoneNumber.length() != 10)
{
sPhoneNumber.setError("please make sure your number is right. ");
sPhoneNumber.requestFocus();
}
else
{
sendVerificationCode(mPhoneNumber);
sPhoneNumber.setError("Shit works");
sPhoneNumber.requestFocus();
// Log.d(Tag, mPhoneNumber);
}
}
});
mSignButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
verifyPhoneNumberWithCode(mVerificationId ,mCode);
}
});
}
private void verifyPhoneNumberWithCode(String verificationId, String aCode)
{
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationId, aCode);
signInWithPhoneAuthCredential(credential);
}
public void sendVerificationCode(String phoneNumber)
{
PhoneAuthProvider.getInstance().verifyPhoneNumber(
"+49" + phoneNumber,        // Phone number to verify
6,                 // Timeout duration
TimeUnit.SECONDS,   // Unit of timeout
this,               // Activity (for callback binding)
mCallbacks);        // OnVerificationStateChangedCallbacks
}

答案1

得分: -1

所以我找到了关于我的问题的答案,因为有人为了相同的问题而来到这里。
问题是当我按下发送验证码按钮时,无法找到mPhoneNumber字符串,也无法在我放置if else语句时找到。所以我做的是将``` mPhoneNumber = sPhoneNumber.getText().toString(); ```语句放在了onClick监听方法中,而不是放在onCreate方法中,而这个onClick监听方法是在onCreate方法中的。所以这是代码:

sPhoneNumber = findViewById(R.id.phoneNumberPrompt);
Code = findViewById(R.id.codePrompt);

mVerificationButton = findViewById(R.id.verificationButton);
mSignButton = findViewById(R.id.signButton);

mCode = Code.getText().toString();

mVerificationButton.setOnClickListener(new View.OnClickListener()
{
mPhoneNumber = sPhoneNumber.getText().toString();

@Override
public void onClick(View view)
{
if (mPhoneNumber.length() != 10)
{
sPhoneNumber.setError("请确保您的号码正确。");
sPhoneNumber.requestFocus();
}
else
{
sendVerificationCode(mPhoneNumber);
sPhoneNumber.setError("成功工作了");
sPhoneNumber.requestFocus();
// Log.d(Tag, mPhoneNumber);
}
}

});


<details>
<summary>英文:</summary>
So i found an answer to my qustion for ant body got here for the same qustions.
the problem was that mPhoneNumber string could not be found ethier when i pressed the button to send the verification and when i put the if else statment if was not found so what i did is put the  ``` mPhoneNumber = sPhoneNumber.getText().toString(); ``` instead from the onCreate method i put it in onClick listner method that was in onCreate method so this is the code 

sPhoneNumber = findViewById(R.id.phoneNumberPrompt);
Code = findViewById(R.id.codePrompt);

mVerificationButton = findViewById(R.id.verificationButton);
mSignButton = findViewById(R.id.signButton);

    mCode = Code.getText().toString();
mVerificationButton.setOnClickListener(new View.OnClickListener()
{
mPhoneNumber = sPhoneNumber.getText().toString();
@Override
public void onClick(View view)
{
if (mPhoneNumber.length() != 10)
{
sPhoneNumber.setError(&quot;please make sure your number is right. &quot;);
sPhoneNumber.requestFocus();
}
else
{
sendVerificationCode(mPhoneNumber);
sPhoneNumber.setError(&quot;Shit works&quot;);
sPhoneNumber.requestFocus();
// Log.d(Tag, mPhoneNumber);
}
}
});

huangapple
  • 本文由 发表于 2020年10月12日 07:45:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/64310083.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定