I am not able to receive “android.provider.Telephony.SMS_RECEIVED” this broadcast in Android Oreo

天涯浪子 提交于 2019-12-29 00:41:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!