我目前正在开发一款使用Android的Android应用NotificationListenerService,这要求用户为我的应用启用通知访问权限Setting -> Security -> Notification Access.
我的问题是,我可以将用户重定向到这个地方,以便他们启用吗?到目前为止,我只能将它们引导到Setting -> Security窗口.
此外,是否可以首先检查用户是否已启用我的应用程序的通知访问权限,然后才重定向它们?
adn*_*eal 23
您可以NotificationAccessSettingsActivity使用以下命令打开Intent,但我不确定是否已检查他们是否已启用您的应用.
startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
Run Code Online (Sandbox Code Playgroud)
或者,对于API 22+:
startActivity(new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS));
Run Code Online (Sandbox Code Playgroud)
非常感谢@adneal 和@Waboodoo。我发布此文章是为了获得完整的答案
使用此方法检查授予或未授予的权限
private boolean isNotificationServiceRunning() {
ContentResolver contentResolver = getContentResolver();
String enabledNotificationListeners =
Settings.Secure.getString(contentResolver, "enabled_notification_listeners");
String packageName = getPackageName();
return enabledNotificationListeners != null && enabledNotificationListeners.contains(packageName);
}
Run Code Online (Sandbox Code Playgroud)
然后根据需要显示设置活动
boolean isNotificationServiceRunning = isNotificationServiceRunning();
if(!isNotificationServiceRunning){
startActivity(new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10296 次 |
| 最近记录: |