Redmi phones not asking SMS permissions and hence not reading sms
Asked Answered
T

1

10

Following is my code:

<!-- Data SMS Receiver -->
    <receiver android:name=".otp.OTPReceiver" android:enabled="true" android:exported="true" >
        <intent-filter>
            <action android:name="android.intent.action.DATA_SMS_RECEIVED" />


            <data android:scheme="sms" />
            <data android:port="9027" />
        </intent-filter>
    </receiver>

otp.OTPReceiver is the associated BroadcastReceiver This works in all other phones except Redmi devices. In Redmi phones you have to manually switch on autostart & other permissions in the Permissions app (This app handles permissions in Redmi phones). I see Facebook, whatsapp, etc. when installed asking the permissions. Would like to know how this can be done.

I saw questions like this & this which are asking the same thing but both are unanswered. I tried adding android:enabled="true", android:exported="true" into the receiver xml snippet like mentioned in here. But none of those are working.

Edit: I'm using data sms (also known as port sms). I verified with normal sms too and the problem exists there too on Redmi phones

Teilo answered 5/7, 2016 at 5:39 Comment(10)
whats your targetSdk?Faradism
targetSdkVersion 24Teilo
I presume you have checked runtime permissions if any !!Faradism
Yup. I am doing that as it works perfectly fine in all other phones.Teilo
see thisFaradism
I know its not answer was trying to convey that its an issue for MI devices, I ran in to same problem but still not figured I think Its because of their custom MIUI OS.Faradism
hey man ping me here if you find anything, it'd be great helpFaradism
@nisarg: Sure. If I find anything, shall update here. Cheers!!Teilo
Any Update guys!!!Precede
Didn't get a solution per say. As an alternative, we are currently reading the SMS programmatically wherever (whichever phones) it is supported. In other scenarios, we let the user type OTP (that's our requirement btw) manually.Teilo
P
2

After Long Time of trying, Got MI SMS permission(Through SMS Provider). Add this Method (content provider method) with your activity or fragment. you will able to get permission.

private void displaySmsLog() {
    Uri allMessages = Uri.parse("content://sms/");
    //Cursor cursor = managedQuery(allMessages, null, null, null, null);  Both are same
    Cursor cursor = this.getContentResolver().query(allMessages, null,
            null, null, null);

    while (cursor.moveToNext()) {
        for (int i = 0; i < cursor.getColumnCount(); i++) {
            Log.d(cursor.getColumnName(i) + "", cursor.getString(i) + "");
        }
        Log.d("One row finished",
                "**************************************************");
    }

}

Give it try , It worked for me.

Precede answered 21/9, 2016 at 11:11 Comment(5)
Thanks, will try this as soon as possible!!Teilo
Hey please provide feedback bro..... Its working on MI 4i... So that I will test and take some precautions for other MI phonePrecede
@PraveenSingh can you please provide information about your testing device.Precede
@TarunSharma I tested on Xiaomi Redmi Note 3Wyn
This works only for normal sms reading . . .OTP passwords are usually sent from SMS Gateways's and that is detected as a Service Message by MIUI and the permission to read that SMS needs to be granted manually.Mord

© 2022 - 2024 — McMap. All rights reserved.