从权限跳转看Activity的data android:scheme

在应用申请悬浮窗权限的时候,可以跳转到相应的设置界面,并且自动切换到应用的条目,高亮显示一下,

android悬浮窗权限怎么申请

在Android中,要申请悬浮窗权限,需要以下步骤:

  1. 在 AndroidManifest.xml 文件中添加权限声明。在 <manifest> 标签内部添加以下代码:

    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
  2. 在你的应用程序中请求悬浮窗权限。可以通过以下代码在你的 Activity 或者 Fragment 中请求权限:

java

复制

复制代码
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(this)) {
    Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                               Uri.parse("package:" + getPackageName()));
    startActivityForResult(intent, REQUEST_CODE);
}

上述代码会打开一个系统设置界面,允许用户授予悬浮窗权限。

而申请通知访问权限时,在跳转的页面中没有高亮显示应用的条目,为什么呢,

因为OverlaySettingsActivity 中设置了 <data android:scheme="package" />

XML 复制代码
packages/apps/Settings/AndroidManifest.xml


<activity 
android:name="Settings$OverlaySettingsActivity" 
android:exported="true" 
android:label="@string/draw_overlay"> 
<intent-filter android:priority="1"> 
<action android:name="android.settings.action.MANAGE_OVERLAY_PERMISSION" /> 
<category android:name="android.intent.category.DEFAULT" /> 
</intent-filter> 
<intent-filter android:priority="1"> 
<action android:name="android.settings.action.MANAGE_OVERLAY_PERMISSION" /> 
<category android:name="android.intent.category.DEFAULT" /> 
<data android:scheme="package" /> 
</intent-filter> 
<meta-data android:name="com.android.settings.FRAGMENT_CLASS" 
android:value="com.android.settings.applications.manageapplications.ManageApplications" /> 
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY" 
android:value="@string/menu_key_apps"/> 
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED" 
android:value="true" /> 
</activity>



<activity 
android:name="Settings$NotificationAssistantSettingsActivity" 
android:exported="true" 
android:label="@string/notification_assistant_title"> 
<intent-filter android:priority="1"> 
<action android:name="android.settings.NOTIFICATION_ASSISTANT_SETTINGS" /> 
<category android:name="android.intent.category.BROWSABLE" /> 
<category android:name="android.intent.category.DEFAULT" /> 
</intent-filter> 
<meta-data android:name="com.android.settings.FRAGMENT_CLASS" 
android:value="com.android.settings.notification.ConfigureNotificationSettings" /> 
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY" 
android:value="@string/menu_key_notifications"/> 
</activity>

附:

android中怎么跳转到NotificationAssistantSettingsActivity

在Android中,没有名为 NotificationAssistantSettingsActivity 的标准活动或类。如果你希望跳转到通知助手设置界面,可以使用以下代码:

Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);

startActivity(intent);

上述代码将打开通知访问权限设置界面,其中用户可以配置通知助手相关的权限。

请注意,根据不同的Android版本和设备制造商,界面的外观和可用选项可能会有所不同。确保你的应用程序具有适当的权限,以请求用户打开通知助手设置界面。

相关推荐
阿巴斯甜18 小时前
Android 报错:Zip file '/Users/lyy/develop/repoAndroidLapp/l-app-android-ble/app/bu
android
Kapaseker18 小时前
实战 Compose 中的 IntrinsicSize
android·kotlin
xq952719 小时前
Andorid Google 登录接入文档
android
黄林晴20 小时前
告别 Modifier 地狱,Compose 样式系统要变天了
android·android jetpack
冬奇Lab1 天前
Android触摸事件分发、手势识别与输入优化实战
android·源码阅读
城东米粉儿1 天前
Android MediaPlayer 笔记
android
Jony_2 天前
Android 启动优化方案
android
阿巴斯甜2 天前
Android studio 报错:Cause: error=86, Bad CPU type in executable
android
张小潇2 天前
AOSP15 Input专题InputReader源码分析
android
_小马快跑_2 天前
Kotlin | 协程调度器选择:何时用CoroutineScope配置,何时用launch指定?
android