对于android10,我们使用RollManger
if (getDefaultSmsPackage(mContext) != null && !getDefaultSmsPackage(mContext).equals(mContext.getPackageName())) {
RoleManager roleManager = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
roleManager = mContext.getSystemService(RoleManager.class);
if (roleManager.isRoleAvailable(RoleManager.ROLE_SMS)) {
if (roleManager.isRoleHeld(RoleManager.ROLE_SMS)) {
Log.d("role", "role");
} else {
Intent roleRequestIntent = roleManager.createRequestRoleIntent(
RoleManager.ROLE_SMS);
((Activity) mContext).startActivityForResult(roleRequestIntent, MESSAGE_CODE);
}
}
}
else {
Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME,
mContext.getPackageName());
((Activity) mContext).startActivityForResult(intent, MESSAGE_CODE);
}
}