简体   繁体   中英

Change default sms app intent not working on android 10

Hello I am working on updating my app compatibility to android 10 and 11 , previously I was making my app to default sms app and receiving and sending new sms from my application , The intent to change default sms app works fine below android 10 but its not showing to change default sms app pop up on android 10

 val intent = Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT)
                            intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, packageName)
                            startActivity(intent)

If anyone know what has changed for android 10 please suggest , because I am not able to find any change for this on developer.android.com , Thanks in advance

After reading documentation carefully , I got they have updated direct intent with roleManager ,

 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
                                val roleManager = getSystemService(RoleManager::class.java)
                                val roleRequestIntent = roleManager.createRequestRoleIntent(RoleManager.ROLE_SMS)
                                startActivityForResult(roleRequestIntent, 12)
                            } else {
                                val intent = Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT)
                                intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, packageName)
                                startActivity(intent)
                            }

This is new way updating all required access for reference :- https://developer.android.com/reference/android/app/role/RoleManager

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM