未调用SmsRetriever.SMS_RETRIEVED_ACTION。我正在使用Firebase Phone Auth:
PhoneAuthProvider.getInstance().verifyPhoneNumber(
mPhoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
activity, // Activity (for callback binding)
mCallbacks); // OnVerificationStateChangedCallbacks
我正在尝试使用SMS Retriever API
检索短信SmsRetrieverClient client = SmsRetriever.getClient(activity);
// Starts SmsRetriever, which waits for ONE matching SMS message until timeout
// (5 minutes). The matching SMS message will be sent via a Broadcast Intent with
// action SmsRetriever#SMS_RETRIEVED_ACTION.
Task<Void> task = client.startSmsRetriever();
task.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
}
});
task.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
});
我正在注册BroadcastReceiver onResume并在暂停时取消注册:
public class MySMSBroadcastReceiver 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);
break;
case CommonStatusCodes.TIMEOUT:
break;
}
}
}
}
可能是Firebase短信格式吗?可能与此不兼容?
提前致谢。
答案 0 :(得分:0)
使用以下依赖项并重试
编译'com.google.android.gms:play-services-auth-api-phone:11.0.4'
答案 1 :(得分:0)
请将依赖项更新为:
implementation "com.google.android.gms:play-services-auth-api-phone:16.0.0"
在 AndroidMaifest.xml 中注册您的广播接收器:
<receiver android:name=".MySMSBroadcastReceiver">
<intent-filter>
<action android:name="com.google.android.gms.auth.api.phone.SMS_RETRIEVED"/>
</intent-filter>
</receiver>
就这样!!。