2
I did work perfectly this notification on android 19 and 21 but does not work on 27, 28 e 29.
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
private void openNotification(){
Intent intent = new Intent( MainActivity.this, NotificationActivity.class );
intent.putExtra( "msg", msg );
intent.putExtra( "status", status );
intent.putExtra( "time", DataTime );
// int id = 1;
int id = (int) (Math.random() * 1000);
PendingIntent pi = PendingIntent.getActivity( getBaseContext(), id, intent, PendingIntent.FLAG_UPDATE_CURRENT );
Notification notification = new Notification.Builder( getBaseContext() ).setContentTitle( "Evento de Pânico" ).setContentText( msg ).setSmallIcon( R.mipmap.panic ).setContentText( DataTime ).setContentIntent( pi ).build();
NotificationManager notificationManager = (NotificationManager) getSystemService( NOTIFICATION_SERVICE );
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify( id, notification );
}
In API 29 comes a warning Toast:
Notification(channel=null pri=0 contentView=null vibrate=null sound=null
defaults=0x0 flags=0x0 color=0x00000000 vis=PRIVATE)
when running in api19 comes the following:
Notification(pri=0 icon=7f0e0005 contentView=br.com.panico/0x109007d vibrate=null sound=null defaults=0x0 flags=0x0 when=1567779581326 ledARGB=0x0 contentIntent=Y deleteIntent=N contentTitle=16 contentText=19 tickerText=N kind=[null])
Related: Configuration of the Notificationcompat
– Icaro Martins