I am in a situation that I need to save the notification even though it is open, at the time of reading the notification I check if it has a connection, if it has it open normally, if it does not, it sends a message stating that it has no connection, is that the notification has already been opened and it disappears, so I wanted it to be saved in that case until the user read with a connection. how do I do? I want before clicking on the notification it will check if it has a connection, if it does not play a msg, and the notification can not disappear. Code:
public void generateNotification () {
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
PendingIntent p = PendingIntent.getActivity(this, 0, new Intent(this,
ReaderNotificacao.class), 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(
this).setLights(Color.WHITE, 500, 500);
builder.setDefaults(0);
builder.setTicker("Fadire");
builder.setContentTitle("Fadire notificação");
builder.setContentText("Você tem uma nova notícia");
builder.setSmallIcon(R.drawable.icone);
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(),
R.drawable.icone));
builder.setContentIntent(p);
Notification n = builder.build();
n.vibrate = new long[] { 150, 300, 150, 600 };
n.flags = Notification.FLAG_AUTO_CANCEL;
nm.notify(R.drawable.ic_launcher, n);
try {
Uri som = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone toque = RingtoneManager.getRingtone(this, som);
toque.play();
} catch (Exception e) {
}
}
Activity to read:
if(verificaConexao())
lerNotificacoes();
else {
Toast.makeText(ReaderNotificacao.this, "Sem conexão, não é possivel ler", 1000).show();
Notification.Builder builder = new Notification.Builder(getApplicationContext());
finish();
}