Redmi phones not asking SMS permissions and hence

2020-07-17 04:28发布

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

1条回答
做个烂人
2楼-- · 2020-07-17 05:00

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.

查看更多
登录 后发表回答