Notification nicht mehr senden nachdem sie geklickt wurde

margerite083

Mitglied
Ich schreibe gerade eine Android App für die Schule.
Darin wird alle 15 Minuten abgefragt ob einer meiner Kontakte Geburtstag hat und wenn ja gibt es eine Notifikation. So weit funktioniert das schon mal. Nun möchte ich aber, wenn die Notification einmal angeklickt wurde, dass sie nicht mehr gesendet wird. Also auch nicht in 15 Minuten, wenn das nächste Mal die Überprüfung ausgeführt wird. Kann mir da jemand helfen?

Java:
public class BirthdayNotifyService extends Service {

    final static String STOP_SERVICE_BROADCAST_KEY="StopServiceBroadcastKey";
    final static int RQS_STOP_SERVICE = 1;
    NotifyServiceReceiver notifyServiceReceiver;
    ArrayList<MyContact> birthdayList;
    private Date geburtstagNeu;
    String notificationText = "Jemand hat Geburtstag!";

    @Override
public void onCreate() {
        notifyServiceReceiver = new NotifyServiceReceiver();
        super.onCreate();
    }

    @Override
public int onStartCommand(Intent intent, int flags, int startId) {
        birthdayList = new BirthdayDataFactory().getContacts(this);
        int mNotificationId = 001;
        Long l = null;

        for (int i = 0; i < birthdayList.size(); i++) {
            geburtstagNeu = birthdayList.get(i).getDate();
            if(geburtstagNeu != null) {
                if(birthdayList.get(i).hasBirthday()) {
                    notificationText = birthdayList.get(i).getName();
                    l = birthdayList.get(i).getID();
                    mNotificationId = Integer.valueOf(l.intValue());

                    NotificationCompat.Builder mBuilder =
                            new NotificationCompat.Builder(this)
                                    .setSmallIcon(R.drawable.ic_launcher)
                                    .setContentTitle("Happy Birthday")
                                    .setContentText(notificationText);

                    // Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, MainActivity.class);

                    PendingIntent resultPendingIntent =
                            PendingIntent.getActivity(
                                    this,
                                    0,
                                    resultIntent,
                                    PendingIntent.FLAG_UPDATE_CURRENT
);

                    mBuilder.setContentIntent(resultPendingIntent);

                    NotificationManager mNotifyMgr =
                            (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

                    // benachrichtigung wird ausgegeben
mNotifyMgr.notify(mNotificationId, mBuilder.build());
                }
            }
        }
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
public void onDestroy() {
        this.unregisterReceiver(notifyServiceReceiver);
        super.onDestroy();
    }

    @Override
public IBinder onBind(Intent arg0) {
        return null;
    }

    public class NotifyServiceReceiver extends BroadcastReceiver {
        @Override
public void onReceive(Context arg0, Intent arg1) {
            int rqs = arg1.getIntExtra(STOP_SERVICE_BROADCAST_KEY, 0);
            if (rqs == RQS_STOP_SERVICE){
                stopSelf();
                ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
                        .cancelAll();
            }
        }
    }
}
 
Zuletzt bearbeitet:
Ähnliche Java Themen
  Titel Forum Antworten Datum
J Notification wird nicht angezeigt wenn App nicht offen ist. Android & Cross-Platform Mobile Apps 6
L Android Sms Notification weiterleiten an PC Android & Cross-Platform Mobile Apps 9
S Notification mit Firebase Notification anpassen Android & Cross-Platform Mobile Apps 1
G Android Push Notification Android & Cross-Platform Mobile Apps 2
T Android Datenbankverbindung in Service für Push Notification Android & Cross-Platform Mobile Apps 0
A Android Notification á la Skype Android & Cross-Platform Mobile Apps 1
G Activity-Wechsel bitte ohne Notification Android & Cross-Platform Mobile Apps 6
W MoveEvent reagiert nicht Game Android & Cross-Platform Mobile Apps 1
W Reward Ads AdMob wird nicht ausgeliefert. Android & Cross-Platform Mobile Apps 9
W Cookie Manger übermittelt nicht Android & Cross-Platform Mobile Apps 1
J Spinner wird nicht aktualisiert Android & Cross-Platform Mobile Apps 6
M PythonInterpreter funktioniert nicht richtig NoClassDefFoundError Android & Cross-Platform Mobile Apps 1
I Android SharedPreferences wenn App auf externem Speicher klappt nicht Android & Cross-Platform Mobile Apps 0
W Frisch generiertes Projekt Value nicht findbar NavController Drawer Android & Cross-Platform Mobile Apps 12
ImageView wird nicht angezeigt Android & Cross-Platform Mobile Apps 4
W WebView Linkvertise lädt nicht richtig oder bleibt grau Android & Cross-Platform Mobile Apps 10
W AlertDialog Eigenschaften existiert nicht mehr. Android & Cross-Platform Mobile Apps 14
W Wieso gehen Log nicht im Service? Android & Cross-Platform Mobile Apps 20
R Android Do not disturb: Sound wird nicht abgespielt Android & Cross-Platform Mobile Apps 2
O Google Admob Ad wird nicht geladen und App stürzt ab Android & Cross-Platform Mobile Apps 1
I Android ListView (Custom) soll auf Hardwaretasten nicht reagieren. Android & Cross-Platform Mobile Apps 10
CT9288 Zufällige Zahlengenerierung scheint nicht richtig zu funktionieren Android & Cross-Platform Mobile Apps 5
M App crasht und ich bekomme es nicht behoben.:( Android & Cross-Platform Mobile Apps 17
M Paper DB wird in Android Studio nicht erkannt Android & Cross-Platform Mobile Apps 7
K Android Android In-App-Purchase lädt nicht Android & Cross-Platform Mobile Apps 0
Besset Android http request an interne ip adresse funktioniert nicht Android & Cross-Platform Mobile Apps 8
R Android Visualizer engine kann nicht initialisiert werden Android & Cross-Platform Mobile Apps 3
OSchriever Navigation drawer Strings ändern sich nicht Android & Cross-Platform Mobile Apps 0
W Code läuft unter SDK 27 aber nicht SDK 30 Android & Cross-Platform Mobile Apps 17
N Android Ich kann mit meiner App nicht auf die Datenbank zugreifen Android & Cross-Platform Mobile Apps 4
A GraphView => X- und Y-Achse wird nicht angezeigt Android & Cross-Platform Mobile Apps 5
ruutaiokwu Android Selbst entwickelter SMTP-Client läuft auf PC, nicht aber auf Android Android & Cross-Platform Mobile Apps 9
W Android Wieso geht getApplicationContext() bei Toast, aber nicht bei AlertDialog.Builder? Android & Cross-Platform Mobile Apps 36
A Android Studio: while-Schleife beginnt nicht Android & Cross-Platform Mobile Apps 5
A jpg wird im Android Studio nicht akzeptiert Android & Cross-Platform Mobile Apps 3
T Android SDK-Manager startet nicht in Eclipse Android & Cross-Platform Mobile Apps 5
J Download und speichern mit jsch klappt nicht Android & Cross-Platform Mobile Apps 5
J Service starte nicht mehr Android & Cross-Platform Mobile Apps 13
Arif Android Radiobutton wird nicht deaktiviert Android & Cross-Platform Mobile Apps 1
Arif Android Canvas wird nicht gezeichnet? Android & Cross-Platform Mobile Apps 0
J Firebase und Emulator startet nicht Android & Cross-Platform Mobile Apps 2
L ListView aktuallisiert sich nicht Android & Cross-Platform Mobile Apps 15
J ArrayAdapter zeigt Liste nicht an Android & Cross-Platform Mobile Apps 0
L Android Animationen werden nicht angezeigt Android & Cross-Platform Mobile Apps 0
Excess Android Service läuft nicht in Sandby weiter Android & Cross-Platform Mobile Apps 2
W Preview wird nicht korrekt angezeigt Android & Cross-Platform Mobile Apps 0
B Profilpic wird nach anmeldung nicht angezeigt. Android & Cross-Platform Mobile Apps 2
K Methode wird nicht gefunden Android & Cross-Platform Mobile Apps 1
J App funktioniert auf Android 5, auf 6 nicht Android & Cross-Platform Mobile Apps 2
K Log.v geht nicht Android & Cross-Platform Mobile Apps 4
J Kamera - Foto wird nicht gespeichert Android & Cross-Platform Mobile Apps 2
L Android Android Studio - Exportierte APK funktioniert nicht Android & Cross-Platform Mobile Apps 6
L Android Methode funktioniert nicht unter Android Android & Cross-Platform Mobile Apps 3
L Android Java scheint XML nicht zu finden Android & Cross-Platform Mobile Apps 11
J android Spinner funktioniert nicht Android & Cross-Platform Mobile Apps 14
B Android osmdroid möchte nicht das es mapnik herunterlädt Android & Cross-Platform Mobile Apps 2
apple_pie1998 SharedPreferences funktionieren nicht... Android & Cross-Platform Mobile Apps 17
S Android neue Version des Programms wird nicht in Emulator geladen Android & Cross-Platform Mobile Apps 1
B Android Textdatei laden (klappt nicht) Android & Cross-Platform Mobile Apps 4
O Android Switch Widget wird nicht angezeigt Android & Cross-Platform Mobile Apps 1
M Android ListView wird nicht dargestellt Android & Cross-Platform Mobile Apps 2
S Android null pointer (ich verstehs nicht) Android & Cross-Platform Mobile Apps 2
S Android Emulator startet nicht vollständig. Android & Cross-Platform Mobile Apps 0
S Neue Activity lässt sich nicht starten Android & Cross-Platform Mobile Apps 28
D Android Tabs nutzen - PagerTitleStrip haut nicht hin Android & Cross-Platform Mobile Apps 4
K MediaPlayer Soundklasse Start und Stop (stop funktioniert nicht) Android & Cross-Platform Mobile Apps 1
O Android Anfänger: Quellcode nicht gefunden Android & Cross-Platform Mobile Apps 3
B Timer geht nicht Android & Cross-Platform Mobile Apps 2
S Umlaute werden trotz UTF-8 nicht angezeigt? Android & Cross-Platform Mobile Apps 6
S SPLIT funktion bei STRING funktioniert nicht! Android & Cross-Platform Mobile Apps 4
J Android Breaking Point in Eclipse hält nicht an? Android & Cross-Platform Mobile Apps 5
J Android SimpleDateFormat parser funktioniert nicht richtig? Android & Cross-Platform Mobile Apps 4
L Android Apache POI: Datei speichern geht nicht Android & Cross-Platform Mobile Apps 1
Y Erstes kleines Android Programm will nicht so recht... Android & Cross-Platform Mobile Apps 1
S Foto-app hält galerie nicht aktuell Android & Cross-Platform Mobile Apps 9
D Man sieht nicht ob Button gedrückt wurde! Android & Cross-Platform Mobile Apps 10
L Android Multitouch will einfach nicht, was mach ich falsch? Android & Cross-Platform Mobile Apps 1
B AlarmManager triggert nicht jede Stunde Android & Cross-Platform Mobile Apps 7
B Erste Android-App: setContentView(R.layout.main) funktioniert nicht Android & Cross-Platform Mobile Apps 6
N Android EditText.setError() funktioniert nicht nach Rotation Android & Cross-Platform Mobile Apps 1
K OnItemLongClickListener in ListActivity spricht nicht an Android & Cross-Platform Mobile Apps 8
N Android Display nicht löschen bzw. neu laden Android & Cross-Platform Mobile Apps 2
J Handy bootet nicht mehr richtig Android & Cross-Platform Mobile Apps 2
D Android OnClickListener funktioniert auf LinearLayout nicht Android & Cross-Platform Mobile Apps 6
X Android Warum werden Views nicht gefunden? Android & Cross-Platform Mobile Apps 4
D Android App startet nicht Android & Cross-Platform Mobile Apps 24
F Android ArrayList nicht funktional in Android!? Android & Cross-Platform Mobile Apps 6
E Datenbankanfrage findet Tabel nicht Android & Cross-Platform Mobile Apps 3
S Android LogCat Ausgaben in Schleife geht nicht? Android & Cross-Platform Mobile Apps 2
schlingel Android Warum man Apps beenden sollte bzw. es nicht tun sollte Android & Cross-Platform Mobile Apps 4
S Auflösungsanpassung funktioniert nicht Android & Cross-Platform Mobile Apps 2
P trotz invalidate() wird onDraw() nicht aufgerufen Android & Cross-Platform Mobile Apps 15
A Werde aus Fehlermeldung nicht schlau.... :-( Android & Cross-Platform Mobile Apps 2
W Eclipse update - Systemprozess reagiert nicht mehr Android & Cross-Platform Mobile Apps 4
B TableLayout verhält sich nicht wie eine Tabelle Android & Cross-Platform Mobile Apps 3
E LayoutInflater funktioniert nicht Android & Cross-Platform Mobile Apps 2
J Sensor Orientierung -> GLRotation stimmt nicht Android & Cross-Platform Mobile Apps 12
K Android Temperaturconverter, R.id.element wird nicht gefunden Android & Cross-Platform Mobile Apps 20
K Android Alarm Manager (Wakelock? ) geht nicht Android & Cross-Platform Mobile Apps 4
U Seit heute morgen läuft meine OpenGL app nicht mehr Android & Cross-Platform Mobile Apps 2

Ähnliche Java Themen

Neue Themen


Oben