То, что я пытаюсь сделать, - это отправить уведомление через менеджер уведомлений, который после щелчка сделает что-то в приложении, только если оно работает в данный момент.я пытался использовать:
notification.contentIntent = PendingIntent.getActivity(this, nNotificationCounter, Someintent, PendingIntent.FLAG_NO_CREATE)
, что всегда вызывало исключение при попытке использовать уведомление.Я переключился на:
Notification notification = new Notification(icon, tickerText, when);
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.some_notification);
contentView.setTextViewText(R.id.title, sTitle);
contentView.setTextViewText(R.id.text, sText);
notification.contentView = contentView;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.number = nNotificationCounter;
Intent notificationIntent = new Intent(this, MainWindow.class).setAction(ACTION_RESET_MESSGE_COUNTER);
notification.contentIntent = PendingIntent.getBroadcast(this, nNotificationCounter, notificationIntent, 0);
и хотя этот код не вызывает исключения.он не вызывает мой BroadcastReceiver, который определен следующим образом:
public class IncomingReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ACTION_RESET_MESSGE_COUNTER)) {
System.out.println("GOT THE INTENT");
return;
}
}
}
и установлен в onCreate:
IntentFilter filter = new IntentFilter(ACTION_RESET_MESSGE_COUNTER);
IncomingReceiver receiver = new IncomingReceiver();
context.registerReceiver(receiver, filter);
Кто-нибудь видит что-то не так с кодом?Или как мне получать сообщения при нажатии на уведомление, но не создавать никаких действий, если оно еще не создано.
edit: добавлено создание намерений и создание уведомлений.
Спасибо, Том