Trying to bring up an unaswered question I found here - How to highlight android setting app menu item?
As seen in this video https://www.youtube.com/watch?v=eHXBc5Mmsqs
The "Power Shade" menu item is being highlighted once you enter the screen. I am trying to add the same feature to my app, guiding users to an item in the settings menu using this highlight feature. I can't seem to find any information on how to actually implement this, nor do I know if it has a specific name I could search for.
Any help would be appreciated!
You can highlight a menu by adding a different background color, text color etc to the particular menu item using custom CSS. To apply custom CSS you need to add CSS class for the menu.
Each time a menu is selected, mouse or keyboard, the Paint event is raised.
It can be achieved by adding the 'e-select' class to the selected menu item using the select event in menu. Whenever the required item is selected in the menu, it will be highlighted by the specified color.
After decompiling the app, here's how it works (simplified):
Intent intent = new Intent("com.samsung.accessibility.installed_service");
if (intent.resolveActivity(context.getPackageManager()) == null) {
intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
}
final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
Bundle bundle = new Bundle();
String showArgs = context.getPackageName() + "/" + MyService.class.getName();
bundle.putString(EXTRA_FRAGMENT_ARG_KEY, showArgs);
intent.putExtra(EXTRA_FRAGMENT_ARG_KEY, showArgs);
intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, bundle);
try {
context.startActivity(intent);
String toastText = "Find PowerShade here";
Toast.makeText(context, toastText, LENGTH_LONG).show();
} catch (Exception e) {
// ask user to grant permission manually
}
Basically it's using undocumented features of Android (see SettingsActivity.java in Android source).
In Kotlin from a Fragment in which you want to check if the user has granted your app notification access. This code will scroll down to the list item and highlight it. Works on Android 11 with a Samsung S20 device. Use onActivityResult() or the new Activity result API inside the Fragment to check if the user has indeed granted the notification access permission.
private fun launchNotificationPermissionSettingsPageAndHighlight[your app]() {
val intent = Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS").apply {
val [your app] = "${requireContext().packageName}/${[your app service]::class.java.name}"
val fragmentKey = ":settings:fragment_args_key"
val showFragmentKey = ":settings:show_fragment_args"
putExtra(fragmentKey, [your app])
putExtra(showFragmentKey, Bundle().apply { putString(fragmentKey, [your app]) })
}
try {
startActivityForResult(intent, requestCodeNotificationPermission)
Toast.makeText(context, "Grant [your app] this permission", LENGTH_LONG).show()
} catch (e: Exception) {
}
}
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