android– 如何获取覆盖不打扰设置值?

android– 如何获取覆盖不打扰设置值?,第1张

概述如何在Android中为我自己的软件包应用程序获取覆盖请勿打扰设置状态?解决方法:documentation不是很清楚如何显示这个选项,只是有可能:OnAndroid8.0(APIlevel26)andabove,userscanadditionallyallownotificationsthroughforapp-specificcategories(alsoknownas

如何在Android中为我自己的软件包应用程序获取覆盖请勿打扰设置状态?

解决方法:

documentation不是很清楚如何显示这个选项,只是有可能:

On AndroID 8.0 (API level 26) and above, users can additionally allow notifications through for app-specific categorIEs (also kNown as channels) by overrIDing Do Not disturb on a channel-by-channel basis. […]
On devices running AndroID 7.1 (API level 25) and below, users can allow notifications through on an app by app basis, rather than on a channel by channel basis.

但根据我的睾丸测试,在AndroID 8.0上,您只能将此选项设置为将importance设置为“紧急”的通知通道,对应于NotificationManager.IMPORTANCE_HIGH.有关创建频道的详细信息,请参阅Create a channel and set the importance.

在AndroID 5.0到7.1上,据说你必须使用setPriority()

On AndroID 8.0 (API level 26) and above, importance of a notification is determined by the importance of the channel the notification was posted to. Users can change the importance of a notification channel in the system settings (figure 12). On AndroID 7.1 (API level 25) and below, importance of each notification is determined by the notification’s priority.

所以我尝试使用NotificationCompat.PRIORITY_MAX,但在添加了system-wide category之前,我没有看到覆盖请勿打扰选项,
就像是:

 NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID)                    .setSmallicon(R.drawable.ic_launcher_foreground)                    .setContentTitle("Notification Title")                    .setContentText("Text content")                    .setPriority(NotificationCompat.PRIORITY_MAX)                    .setcategory(NotificationCompat.category_ALARM);

现在,对于AndroID 8.0,要查看用户已对您的频道应用了哪些设置,Read notification channel settings建议使用来自getNotificationChannel()的canBypassDnd():

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {        notificationmanager manager = (notificationmanager) getSystemService(Context.NOTIFICATION_SERVICE);        NotificationChannel channel = manager.getNotificationChannel(CHANNEL_ID);        channel.canBypassDnd();    }

不幸的是,在7.1下似乎没有任何公共方法来获取该信息;唯一可用于notificationmanagerCompat的是areNotificationsEnabled().

总结

以上是内存溢出为你收集整理的android – 如何获取覆盖不打扰设置值?全部内容,希望文章能够帮你解决android – 如何获取覆盖不打扰设置值?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1104860.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存