I wanted to know how to call a method when I click on a notification, I do not want it to call a Activity
, but only a method that has within the same class.
Example:
public void gerarNotificacao(){
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
PendingIntent p = PendingIntent.getActivity(this, 0, new Intent(this, Util.class), 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setTicker("Ticker Texto");
builder.setContentTitle(" 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){}
}