问题
This is my Menifest file
<receiver
android:name="com.agribazaar.android.receivers.OTPReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
This is my Broadcast Receiver class
public class OTPReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")){
}
}
回答1:
This fixed the issue for me - I wasn't explicitly requesting permission at runtime for android.Manifest.permission.RECEIVE_SMS. In earlier versions of android it was working fine but in android O devices i got the issue.
int SMS_PERMISSION_REQ_CODE_SUBMIT = 101;
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.RECEIVE_SMS)
!= PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(SmsActivity.this, new String[]{Manifest.permission.RECEIVE_SMS},
SMS_PERMISSION_REQ_CODE_SUBMIT);
}
来源:https://stackoverflow.com/questions/47674092/i-am-not-able-to-receive-android-provider-telephony-sms-received-this-broadcas