NotificationManager causes error java.util.ArrayList can not be cast to java.lang.CharSequence [closed]

4

I'm doing an Android app and am having a question while generating a notification.

Here's a snippet of code:

public void gerarNotificacao(View view) { 
  NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

  SimpleDateFormat datas = new SimpleDateFormat("dd/mm/yyyy");

  mDiasdaSem = String.valueOf(datas.format(new Date())); 

  eventoDao = new eventosDao(this);
  eventoDao.open();

  String filtro = mDiasdaSem;
  List<Eventos> eventos = eventoDao.listarEventos(filtro);

  NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
  builder.setTicker("Ticker Texto");
  builder.setTicker( (CharSequence) eventos);
  builder.setSmallIcon(R.drawable.ic_launcher);

  Notification n =   builder.build();

  n.vibrate = new long[]{250, 300, 150, 600};
  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)
  {         
  }
}

The following error occurs:

  

java.util.ArrayList can not be cast to java.lang.CharSequence

How to solve?

    
asked by anonymous 07.12.2014 / 19:01

1 answer

0

Try to put it this way:

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Notification nt = null;

    nt = new Notification(R.drawable.ic_launcher, "Status Replicação", System.currentTimeMillis());
    nt.flags = Notification.FLAG_AUTO_CANCEL;

    PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(getApplicationContext(), Activity_Principal.class), 0);
    nt.setLatestEventInfo(this, "Status Replicação", "Replicação feita com sucesso, total: "+totalReplicado, pi);

    nt.vibrate = new long[]{250, 300, 150, 600};
    notificationManager.notify((int)Math.round(Math.random()), nt);
    
07.12.2014 / 19:37