I was able to set the app as a default messaging app with the below code
Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME,
getPackageName());
startActivityForResult(intent, SET_AS_DEFAULT_INTENT);
But this works only on API <= 28 (Android 9 or below)
But this is not working on Android 10 or above.
Am I missing something? I heard about using a role manager but it is not working for me.
RoleManager roleManager = getSystemService(RoleManager.class);
if (roleManager.isRoleAvailable(RoleManager.ROLE_SMS)) {
if (roleManager.isRoleHeld(RoleManager.ROLE_SMS)) {
} else {
Intent roleRequestIntent = roleManager.createRequestRoleIntent(
RoleManager.ROLE_SMS);
startActivityForResult(roleRequestIntent, SET_AS_DEFAULT_INTENT);
}
}