gpt4 book ai didi

android - 无法以编程方式从小米手机读取消息

转载 作者:太空狗 更新时间:2023-10-29 16:27:15 25 4
gpt4 key购买 nike

我正在使用 EasyPermission 从用户那里获取权限

@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);
}
}

他们有什么办法可以读取来自小米 设备的所有消息吗?

最佳答案

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

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);
}
}

}

关于android - 无法以编程方式从小米手机读取消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47714747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com