我已将此广播接收器注册为片段,并等待自动读取otp但从未达到onRecieve()方法。请帮忙。
IntentFilter intentFilter = new IntentFilter("SmsMessage.intent.MAIN");
mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String msg = intent.getStringExtra("get_msg");
msg = msg.replace("\n", "");
String body = msg.substring(msg.lastIndexOf(":") + 1, msg.length());
String pNumber = msg.substring(0, msg.lastIndexOf(":"));
mOtp1.setText(pNumber.trim());
if (pNumber.equalsIgnoreCase(sms)) {
mAutoImg.setVisibility(View.VISIBLE);
}
}
};
getContext().registerReceiver(this.mIntentReceiver, intentFilter);
答案 0 :(得分:0)
意图过滤器使用错误
IntentFilter intentFilter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");