Ich möchte einige Methoden ausführen, wenn ich auf Notification Action Button klicke. Ich habe auf dieser Seite gesucht, aber alles scheint in Ordnung zu sein und mein IntentService wird nicht aufgerufen.IntentService onHandleEvent() startet nicht
Meine Aktion-Button-Intent
Intent off = new Intent();
off.setAction("action");
off.putExtra("test", "off");
PendingIntent pOff = PendingIntent.getService(context, 22, off, 0);
Builder Mitteilung
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(/**/)
.setContentTitle(/**/)
.setContentText(/**/)
.addAction(/**/, "Off", pOff)
.setContentIntent(pendingIntent)
.setDefaults(Notification.DEFAULT_SOUND)
.setAutoCancel(true);
Intent Service Class
public class NotificationServiceClass extends IntentService {
public NotificationServiceClass(String name) {
super(name);
}
public NotificationServiceClass() {
super("NotificationServiceClass");
}
@Override
protected void onHandleIntent(Intent intent) {
Log.i("test", "onHandle");
if (intent.getAction().equals("action")) {
Log.i("test", "action");
Bundle bundle = intent.getExtras();
if (bundle != null) {
Log.i("test", "onHandleBundleNotNull");
if (bundle.containsKey("test")) {
Log.i("test", bundle.getString("test"));
}
}
}
}
}
XML-Deklaration für Service-Klasse
<service
android:name=".Manager.NotificationServiceClass"
android:exported="false">
</service>
Das war ein wirklich dummer Fehler. Vielen Dank für den Hinweis. –