当我收到奥利奥OTP SmsBroadcastReceiver没有触发。 我已经明确地注册我的接收机片段,而不是不仅体现。
public class MyFragment extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
intentFilter = new IntentFilter();
intentFilter.addAction(Telephony.Sms.Intents.SMS_RECEIVED_ACTION);
smsBroadcastReceiver = new SmsBroadcastReceiver();
getActivity().registerReceiver(smsBroadcastReceiver,intentFilter);
return inflater.inflate(
R.layout.fragment_two, container, false);
}
}
这是我的SmsReceiverBroadcast类
public class SmsBroadcastReceiver extends BroadcastReceiver {
public SmsBroadcastReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
Log.d("onRecieve","Otp has been received");
}
} catch (Exception e) {
}
}
}
而在我的表现,
<receiver
android:name=".receiver.SmsBroadcastReceiver"
android:enabled="true"
android:exported="false"
>
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
我没有收到在覆盖所有触发的onReceive的广播接收机()方法。 我发现,我们需要明确注册的广播接收器。 我注册使用registerBroadcast()我的接收器,它是不工作的me.Also,我提到https://developer.android.com/about/versions/oreo/background.html
我也曾尝试是否需要添加任何其他许可登记,并触发接收器,每当我收到OTP?是我的意图过滤器的操作(Telephony.Sms.Intents.SMS_RECIEVED_ACTION)是否正确?