Read OTP/SMS in MI device not working (Android) -


i have integrated auto read otp in code , it's working fine except in miui devices. broadcastreceiver never wake in case of mi devices when sms received. after efforts think mi devices runs on permission manager permissions regarding read sms disabled default comes in category of privacy permissions , looks : enter image description here

now can't figure out way notify user first accept or decline permission. device disable permissions default after app installed in device.is there way notify user accept permission's when app installed ?

some code:

smsreciever.class - broadcastreceiver wakes when sms received.

public class smsreciever extends broadcastreceiver { private static final string otp_length = "6"; private string otp = ""; private imessagecallback callable; private static final string tag = smsreciever.class.getsimplename();  @override public void onreceive(context context, intent intent) {     bundle bundle = intent.getextras();     smsmessage[] msgs = null;      if (bundle != null) {          object[] pdus = (object[]) bundle.get("pdus");         msgs = new smsmessage[pdus.length];          (int = 0; < msgs.length; i++) {              msgs[i] = smsmessage.createfrompdu((byte[]) pdus[i]);              try {                 string sender = msgs[i].getoriginatingaddress();                  string phonenumber = msgs[i].getdisplayoriginatingaddress();                 log.d(tag, "onreceive: phone " + phonenumber);                 string message = msgs[i].getmessagebody();                 log.d(tag, "onreceive: phone " + message);                  otp = getotp.extractotp(message, otp_length);                  if (null != sender && message.contains("otp appname") && !textutils.isempty(otp)) {                     if (callable != null)                         callable.getotp(otp);                 }              } catch (illegalargumentexception e) {                 e.printstacktrace();             }         }     } }  public void setmessagecallable(imessagecallback callable) {     this.callable = callable; }  public interface imessagecallback {     void getotp(string otp); } } 

andridmanifest.xml - permissions receive , read sms

<uses-permission android:name="android.permission.receive_sms"/> <uses-permission android:name="android.permission.read_sms"/> 

mi devices can set permissions per app. can plz check if app has sms permission enabled.

you need go settings > apps > {your_app} > permissions , check if sms permission enabled. xiaomi phones provide per app permissions.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -