Хотя ответ @cja может быть правильным, хотя ему не хватает нескольких строк кода (Уведомление не будет отображаться или не будет отображаться на панели уведомлений).
Это полная рабочая функция:
public void createNotification() {
NotificationCompat.Builder notification = new NotificationCompat.Builder(this);
notification.setTicker( "Ticker Text" );
notification.setSmallIcon(R.drawable.ic_launcher);
notification.setContentTitle( "Content Title" );
notification.setContentText( "Content Text" );
notification.setAutoCancel( false );
notification.setOngoing( true );
notification.setNumber( ++NotificationCount );
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
notification.setContentIntent(pIntent);
notification.build();
NotificationManager nManger = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nManger.notify(NotificationID, notification.build());
}
NotificationID is int служит идентификатором вашего уведомления.
, вы можете очистить его, используя это:*
убедитесь, что notification.setAutoCancel( false );
установлен на false , поэтому он не будет очищен при нажатии кнопки очистки или при наличии жеста смахивания.
несколько строк кодов изначально@cja пост.
ура / счастливое кодирование ...