如何请求/检查将短信发送到mi设备中的多个收件人的权限?

时间:2018-08-06 10:22:00

标签: android android-permissions miui

我试图将SMS发送给多个联系人,它可以与其他设备正常工作,但是当我在mi设备中运行它时,它会询问每个联系人的权限。 (例如,如果有4位联系人,它将要求4次拒绝一次或允许一次)

enter image description here

我的代码如下:

private void invite() {
    for(int i=0;i<selectedContactPosList.size();i++){

        int pos=selectedContactPosList.get(i);
        Contact contact=contactList.get(pos);
        sendSMS(contact.getPhoneList().get(0),"Testing message from Veri Doc Global",pos);
    }

private void sendSMS(final String phoneNumber, String message, final int pos)
    {
        String SENT = "SMS_SENT";
        String DELIVERED = "SMS_DELIVERED";

        PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
                new Intent(SENT), 0);

        PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
                new Intent(DELIVERED), 0);

        //---when the SMS has been sent---
        registerReceiver(new BroadcastReceiver(){
            @Override
            public void onReceive(Context arg0, Intent arg1) {
                switch (getResultCode())
                {
                    case Activity.RESULT_OK:
                        sentContacts.put(pos,true);
                        Log.e("sms sent success",phoneNumber);
                        break;

                    default:
                        sentContacts.put(pos,false);
                        Log.e("sms sent failure",phoneNumber);

                }

                if(sentContacts.size()==selectedContactPosList.size()){
                    showResult();
                }
                unregisterReceiver(this);
            }
        }, new IntentFilter(SENT));

        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
    }

如何克服这个问题?

我要检查的是是否授予许可?如果没有,我将其重定向到权限设置。但我不知道如何在miui中检查权限。

当我尝试运行以下代码时,我总是在MiUi中得到PERMISSION_GRANTED

private boolean checkForPermission() {
    int rcContact = ContextCompat.checkSelfPermission(LevelActivity.this, Manifest.permission.READ_CONTACTS);
    int rcSMS= ContextCompat.checkSelfPermission(LevelActivity.this, Manifest.permission.SEND_SMS);

    return rcContact == PackageManager.PERMISSION_GRANTED && rcSMS == PackageManager.PERMISSION_GRANTED;
}

0 个答案:

没有答案