我尝试在 Android 应用程序中实现请求短信验证,我的代码在调试中就像一个魅力,但是当我生成签名 apk 应用程序并将它作为发布运行时,我的 BroadcastReceiver 类似乎没有执行,我尝试了很多方法,比如将我的接收器定义为内部类活动,但仍然是同样的问题!
应用程序标签清单中的定义:
<receiver android:name="com.hellow.CustomViews.BroadcastReceiverr" android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.auth.api.phone.SMS_RETRIEVED"/>
</intent-filter>
</receiver>
这是我的接收器类:
public class BroadcastReceiverr extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (SmsRetriever.SMS_RETRIEVED_ACTION.equals(intent.getAction())) {
contextt = context;
prefs = contextt.getSharedPreferences("MyPrefsFile", MODE_PRIVATE);
editor = prefs.edit();
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);
Toast.makeText(context, "done", Toast.LENGTH_SHORT).show();
Log.d("messageeeeee",message);
// 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 ...
Log.d("Faileddd","dfg");
break;
}
}
这是 SmsRetrieverClient 的初始化:
SmsRetrieverClient client = SmsRetriever.getClient(this);
Task<Void> task = client.startSmsRetriever();
task.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.d("onSuccess","onSuccessssssssssss");
}
});
task.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d("onFailure","onFailureeeeee");
}
});
但我想知道接收器方法如何在调试中执行和烤面包“完成”,但在发布中没有!