我一直在尝试实现 Google API(https://developers.google.com/identity/sms-retriever/user-consent/request),并且我从 public static final String EXTRA_CONSENT_INTENT = 获取空值“com.google.android.gms.auth.api.phone.EXTRA_CONSENT_INTENT”;
这是我的 consentIntent 变量
val consentIntent : Intent? = extras.getParcelable(SmsRetriever.EXTRA_CONSENT_INTENT)
我不能将 consentIntent 设置为 null,因为需要从客户端应用程序启动“用户同意”对话框。
请帮助我解决这个错误。
预先感谢。
您需要使用正确的依赖项。我用那些:
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'com.google.android.gms:play-services-auth-api-phone:17.4.0'
另外,这是我的广播接收器类,我的意图不为空(使用断点检查):
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:
Intent consentIntent = extras.getParcelable(SmsRetriever.EXTRA_CONSENT_INTENT);
try {
consentIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(consentIntent);
} catch (ActivityNotFoundException e) {
}
break;
case CommonStatusCodes.TIMEOUT:
break;
}
}
}
}