Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android notification turn on banner setting programmatically

Is there any ways for turning on the banners setting (display on top of the status bar) in application notification programmatically?

enter image description here

<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>
like image 884
cwai Avatar asked Jun 23 '17 01:06

cwai


1 Answers

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).

like image 101
Timon Avatar answered Nov 15 '22 00:11

Timon