-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
是否有人曾提过类似的问题?
否(No)
你觉得APP有什么不足之处?
核心代码
createRequestRoleIntent(RoleManager.ROLE_SMS)
fun requestDefaultSmsRole(activity: Activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// Android 10+ 使用 RoleManager
val roleManager = activity.getSystemService(Context.ROLE_SERVICE) as? RoleManager
if (roleManager?.isRoleAvailable(RoleManager.ROLE_SMS) == true) {
val intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_SMS)
activity.startActivityForResult(intent, REQUEST_CODE_SET_DEFAULT_SMS)
}
} else {
// 老版本使用 ACTION_CHANGE_DEFAULT
val intent = Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT).apply {
putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, activity.packageName)
}
activity.startActivityForResult(intent, REQUEST_CODE_SET_DEFAULT_SMS)
}
}
你觉得该怎么去完善会比较好?【非必答】
No response