我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
设备读取所有消息吗?