I've successfully modified my app to be used as default sms app. The problem is with the dialog that should prompt user to set my app as default. It seems to work on older versions, but not on android 10 emulator.
My code:
fun Activity.askToBeDefaultSMSApp() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
val intent = Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT)
intent.putExtra(
Telephony.Sms.Intents.EXTRA_PACKAGE_NAME,
packageName
)
startActivityForResult(intent, DEFAULT_SMS_APP_PERMISSION_REQUEST)
}
}
I do get onActivityResult response which says that permission is granted, yet if I call:
Telephony.Sms.getDefaultSmsPackage(this)
I still see google sms app as default.
What could be wrong?
For android 10 we use 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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With