Eu estou fazendo uma aplicação Android e estou com uma dúvida ao gerar uma notificação.
Aqui estarei disponibilizando um trecho do código:
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)
{
}
}
O seguinte erro ocorre:
java.util.ArrayList cannot be cast to java.lang.CharSequence
Como resolver?
setTicker()
. Não se pode fazer umcast
de umaArrayList<>
para umCharSequence
. Poste o código de sua classe Evento também.ArrayList<>
!