I am not able to receive “android.provider.Telepho

2019-01-20 11:08发布

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条回答
祖国的老花朵
2楼-- · 2019-01-20 11:38

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);
}
查看更多
登录 后发表回答