更改在Android 10上的默认短信应用意图不起作用。

huangapple go评论73阅读模式
英文:

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"

英文:

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

答案1

得分: 6

阅读文档后,我了解到他们通过 RoleManager 更新了直接意图(direct intent)的方法,

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

这是一种更新所需访问权限的新方式,供参考:
https://developer.android.com/reference/android/app/role/RoleManager

英文:

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

huangapple
  • 本文由 发表于 2020年9月30日 18:31:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/64135681.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定