Android通知以编程方式打开横幅设置 [英] Android notification turn on banner setting programmatically
本文介绍了Android通知以编程方式打开横幅设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以通过任何方式在应用程序通知中打开横幅设置(显示在状态栏顶部)?
Is there any ways for turning on the banners setting (display on top of the status bar) in application notification programmatically?
<pre><code>
// send notification to NotificationManager
Notification.Builder notificationBuilder =new Notification.Builder(context);
notificationBuilder.setSmallIcon(R.drawable.icon_32x32)
.setLargeIcon(bitmap)
.setContentTitle("title")
.setContentText("content")
.setContentIntent(contentIntent)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setPriority(Notification.PRIORITY_HIGH)
.setCategory(Notification.CATEGORY_MESSAGE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
notificationBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
}
NotificationManager notificationManager =
(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(id, notificationBuilder.build());
</code></pre>
推荐答案
相同的问题. 我只需在AndroidManifest.xml中添加ACCESS_NOTIFICATION_POLICY权限即可解决此问题:
Same problem. I solved this issue simply adding in the AndroidManifest.xml the ACCESS_NOTIFICATION_POLICY permission:
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
不需要(至少对我来说).
Nothing more is required (at least for me).
这篇关于Android通知以编程方式打开横幅设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文