有什么方法可以以编程方式打开应用程序通知中的横幅设置(显示在状态栏顶部)?
<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权限即可解决此问题:
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
不需要更多(至少对我而言)。