简体   繁体   English

如何使用代码以编程方式在 android 设备中启用浮动通知

[英]how to programmatically enable floating notification in android device using code

Be informed we are using heads up notification in our android app up to alert our users.被告知我们正在我们的 android 应用程序中使用抬头通知来提醒我们的用户。 Code is working fine as long as we manually go to settings and enable floating notification in our Xiaomi Redmi 9a Device.只要我们手动进入设置并在我们的小米 Redmi 9a 设备中启用浮动通知,代码就可以正常工作。 Otherwise, it works just like regular notification with just icon on top of status bar waiting for us to pull it down to see the message否则,它就像常规通知一样工作,状态栏顶部只有图标等待我们将其拉下以查看消息

Based on some threads, we tried using this line to switch on floating notification by default基于一些线程,我们尝试使用此行默认打开浮动通知

<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />

But ,end result is same.但是,最终结果是一样的。 But seriously speaking, how can we expect a user to go down so deep in settings and enable it.但说真的,我们怎么能指望用户深入设置并启用它。 I mean its ridiculous.我的意思是它很荒谬。 Is there any way we can get around this issue ?有什么办法可以解决这个问题吗?

  1. Declare the permission in the app manifest在应用清单中声明权限

    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

  2. Check the Permission检查权限

    ContexCompat.checkSelfPermission(this,Manifest.permission.POST_NOTIFICATION)==PackageManager.PERMISSION_GRANTED { sendNotification(this) }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android - 如何使用代码允许/启用“浮动通知”设置作为应用程序的默认设置 - Android - How to allow/enable “Floating notifications” setting as default for App using code 如何在xamarin.android中启用浮动通知和锁屏通知(Java或Kotlin都可以) - how to enable floating notification and lock screen notification in xamarin android(Java or Kotlin is okay) 如何在Delphi中以编程方式在android设备上启用wi-fi? - How to programmatically enable wi-fi on android device in Delphi? 如何在Android 4.0设备上以编程方式启用USB网络共享? - How I can enable USB Tethering programmatically on an Android 4.0 device? 如何使用FCM将FCM中的通知从一台设备发送到另一台设备 - How to send Notification using FCM from one device to another using code Android 如何通过 delphi 代码在 android 设备上启用 HotSpot - How can enable HotSpot on android device by delphi code 以编程方式启用通知渠道 - Enable notification channels programmatically 如何在Android中以编程方式启用动画 - How to enable Animation programmatically in Android 如何在Android中以编程方式启用HSDPA? - How to enable HSDPA programmatically in Android? 如何以编程方式启用自动启动和浮动 window 权限 - How to programmatically enable auto start and floating window permissions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM