Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
364 views
in Technique[技术] by (71.8m points)

android - Redmi phones not asking SMS permissions and hence not reading sms

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...