[英]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 ?有什么办法可以解决这个问题吗?
Declare the permission in the app manifest在应用清单中声明权限
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
Check the Permission检查权限
ContexCompat.checkSelfPermission(this,Manifest.permission.POST_NOTIFICATION)==PackageManager.PERMISSION_GRANTED { sendNotification(this) }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.