我无法在Android Oreo中收到此广播的"android.provider.Telephony.SMS_RECEIVED" [英] I am not able to receive “android.provider.Telephony.SMS_RECEIVED” this broadcast in Android Oreo

查看:332
本文介绍了我无法在Android Oreo中收到此广播的"android.provider.Telephony.SMS_RECEIVED"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的清单文件

<receiver
android:name="com.agribazaar.android.receivers.OTPReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>

这是我的广播接收器课程

public class OTPReceiver extends BroadcastReceiver {
   @Override
public void onReceive(Context context, Intent intent) {        
if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")){

}
}

推荐答案

这为我解决了这个问题- 我没有在运行时明确要求android.Manifest.permission.RECEIVE_SMS的权限. 在早期版本的android中,它工作正常,但在android O设备中,我遇到了问题.

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);
}

这篇关于我无法在Android Oreo中收到此广播的"android.provider.Telephony.SMS_RECEIVED"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆