I am using bubble feature in my app for Android 10. So I need to ask permission to enable Bubble feature. If users agree to the permission, then need to go through the exact path of enabling it. How do I achieve that. Thanks in advance.
Asked
Active
Viewed 681 times
1
-
Bubbles are not available for users on Android 10 -- it is a developer-only feature. Bubbles are enabled for users on Android R, and there is no permission needed to use them. – CommonsWare May 12 '20 at 12:24
-
@CommonsWare thank you..can we programmatically enable it? – Kousalya May 12 '20 at 12:26
-
1On Android 10? Not that I am aware of. Those developer toggles usually are not exposed to be changed programmatically. – CommonsWare May 12 '20 at 12:46
1 Answers
1
I can answer this for Android 11.
This first method will check if Bubbles are enabled or not.
/** Returns true if bubbles are enabled for this app */
private boolean canDisplayBubbles() {
if (Build.VERSION.SDK_INT < MIN_SDK_BUBBLES) {
return false;
}
// NotificationManager#areBubblesAllowed does not check if bubbles have been globally disabled,
// so we use this check as well.
boolean bubblesEnabledGlobally;
try {
bubblesEnabledGlobally = Settings.Global.getInt(getContentResolver(), "notification_bubbles") == 1;
} catch (Settings.SettingNotFoundException e) {
// If we're not able to read the system setting, just assume the best case.
bubblesEnabledGlobally = true;
}
NotificationManager notificationManager = getSystemService(NotificationManager.class);
return bubblesEnabledGlobally && notificationManager.areBubblesAllowed();
}
This second method will launch a settings page asking the user to give permission for your app to display Bubbles.
/** Launches a settings page requesting the user to enable Bubbles for this app */
private void requestBubblePermissions() {
startActivityForResult(
new Intent(Settings.ACTION_APP_NOTIFICATION_BUBBLE_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName()),
REQUEST_CODE_BUBBLES_PERMISSION);
}

Will Harmon
- 11
- 1
-
Nice catch with the global settings. If disabled globally apps probably wants to send the user to `android.settings.NOTIFICATION_SETTINGS` where that setting lives. – Roy Solberg Nov 05 '20 at 10:40
-
ACTION_APP_NOTIFICATION_BUBBLE_SETTINGS seemed to handle the case where it's globally disabled quite well, at least on Pixel, so I opted to not differentiate the two cases. – Will Harmon Nov 08 '20 at 22:21