突出显示系统设置中的菜单项

Highlighting a menu item in system settings

试图提出我在这里发现的一个未回答的问题 - How to highlight android setting app menu item?

如本视频所示https://www.youtube.com/watch?v=eHXBc5Mmsqs

进入屏幕后,“Power Shade”菜单项将突出显示。我正在尝试向我的应用程序添加相同的功能,使用此突出显示功能将用户引导至设置菜单中的项目。我似乎找不到任何关于如何实际实现它的信息,我也不知道它是否有我可以搜索的特定名称。

如有任何帮助,我们将不胜感激!

反编译应用程序后,它的工作原理如下(简化):

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
}

基本上它使用了 Android 的未记录的功能(参见 Android 来源中的 SettingsActivity.java)。

在 Kotlin 中的片段中,您要在其中检查用户是否已授予您的应用通知访问权限。此代码将向下滚动到列表项并将其突出显示。使用三星 S20 设备在 Android 11 上工作。使用 onActivityResult() 或 Fragment 中的新 Activity result API 来检查用户是否确实授予了通知访问权限。

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

为想要高亮 Settings.ACTION_MANAGE_OVERLAY_PERMISSION 或其他权限的人提供的解决方案。 AppSettings -> Highlight Permission

Settings.ACTION_MANAGE_OVERLAY_PERMISSION 示例:

private const val EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key"
private const val EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args"
private const val EXTRA_SYSTEM_ALERT_WINDOW = "system_alert_window"

fun askForOverlayPermission(context: Context) {
    val intent = Intent(
        Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
        Uri.parse("package:${context.packageName}")
    ).highlightSettingsTo(EXTRA_SYSTEM_ALERT_WINDOW)
    context.startActivity(intent)
}

private fun Intent.highlightSettingsTo(string: String): Intent {
    putExtra(EXTRA_FRAGMENT_ARG_KEY, string)
    val bundle = bundleOf(EXTRA_FRAGMENT_ARG_KEY to string)
    putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, bundle)
    return this
}

Keys for permission. install_other_appsalarms_and_remindersdefault_browser