本文介绍: 请注意,根据不同的Android版本设备制造商,界面的外观和可用选项可能会有所不同。确保你的应用程序具有适当的权限,以请求用户打开通知助手设置界面。在应用申请悬浮权限的时候,可以跳转到相应的设置界面,并且自动切换到应用的条目,高亮显示一下,上述代码将打开通知访问权限设置界面,其中用户可以配置通知助手相关的权限。而申请通知访问权限时,在跳转的页面中没有高亮显示应用的条目,为什么呢,上述代码会打开一个系统设置界面,允许用户授予悬浮窗权限。android悬浮窗权限怎么申请。

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

android悬浮窗权限怎么申请

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

  1. 在 AndroidManifest.xml 文件添加权限声明。在 <manifest&gt; 标签内部添加以下代码:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/&gt;
  1. 在你的应用程序请求悬浮窗权限。可以通过以下代码在你的 Activity 或者 Fragment 中请求权限:

java

复制

if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M &amp;&amp; !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” />



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版本设备制造商,界面的外观和可用选项可能会有所不同。确保你的应用程序具有适当的权限,以请求用户打开通知助手设置界面。

原文地址:https://blog.csdn.net/aaajj/article/details/134563257

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。

如若转载,请注明出处:http://www.7code.cn/show_1825.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注