2

EasyPermission习惯于permissions从用户那里获取。

@AfterPermissionGranted(PERMISSIONS_REQUEST_READ_SMS)
private void readSMS() {
    String[] perms = {Manifest.permission.READ_SMS};
    if (EasyPermissions.hasPermissions(this, Manifest.permission.READ_SMS)) {
        initSMS();
    } else {
        // Do not have permissions, request them now
        EasyPermissions.requestPermissions(this, getString(R.string.send_sms_rationale),
                PERMISSIONS_REQUEST_READ_SMS, Manifest.permission.READ_SMS);
    }
}

initSMS() 曾尝试从 Android 设备读取消息。它适用于除设备以外的所有Xiaomi设备。我用TelephonyProvider类来阅读消息。

private void initSMS() {
    TelephonyProvider provider = new TelephonyProvider(this);
    List<Sms> sms = provider.getSms(TelephonyProvider.Filter.INBOX).getList();
    for(int i = 0; i <= sms.size() - 1; i++) {
        Log.d("Address",sms.get(i).address);
        Log.d("Sms",sms.get(i).body);
        Log.d("ReceivedDate",""+sms.get(i).receivedDate));
        Log.d("State",""+sms.get(i).status);
        Log.d("person",""+sms.get(i).person);
    }
}

他们有什么方法可以从Xiaomi设备读取所有消息吗?

4

1 回答 1

5

我希望这对你有用。首先你必须调用函数 isMIUI() 来检查 miui mobile,然后调用上面的函数。此功能将重定向到获取服务短信权限的设置。

private void onDisplayPopupPermission() {

        try {
            // MIUI 8
            Intent localIntent = new Intent("miui.intent.action.APP_PERM_EDITOR");
            localIntent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity");
            localIntent.putExtra("extra_pkgname", getPackageName());
            localIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            localIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(localIntent);


        } catch (Exception e) {
            try {
                // MIUI 5/6/7
                Intent localIntent = new Intent("miui.intent.action.APP_PERM_EDITOR");
                localIntent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity");
                localIntent.putExtra("extra_pkgname", getPackageName());
                localIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                localIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(localIntent);


            } catch (Exception e1) {
                // Otherwise jump to application details
                Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                Uri uri = Uri.fromParts("package", getPackageName(), null);
                intent.setData(uri);
                startActivity(intent);
            }
        }

    }
于 2018-02-21T09:59:32.360 回答