Frage zu Notification Builder

  • 0 Antworten
  • Letztes Antwortdatum
kukuk

kukuk

App-Anbieter (kostenlos)
37
Ich habe das Problem, dass ich nicht mehr weiter komme. Ich erstelle Eine Benachrichtigung mit 2 Icons. Wenn ich man auf die Icons klickt, soll ein Code ausgeführt werden, und die Benachrichtigung verschwinden. Kann mir jemand helfen wie ich das mache?
Momentan öffnet sich immer wieder die MainActivity und die Meldung verschwindet nicht.

Ich erstelle mit folgendem Code meine Benachrichtigung:

if (file.exists()){
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.cancel(getIntent().getIntExtra(NOTIFICATION_ID, -1));
notification_2_0();


public void notification_2_0(){
Context context = this;
int notificationId =4; // just use a counter in some util class...
PendingIntent dismissIntent = MainActivity.getDismissIntent(notificationId, context);


NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
//builder.setPriority(NotificationCompat.PRIORITY_MAX) //HIGH, MAX, FULL_SCREEN and setDefaults(Notification.DEFAULT_ALL) will make it a Heads Up Display Style
// builder.setDefaults(Notification.DEFAULT_ALL) // also requires VIBRATE permission
builder.setSmallIcon(R.drawable.main_icon1) // Required!
.setOngoing(true)
.setContentTitle("Die Stempeluhr läuft!")
.setContentText("")
.setAutoCancel(true)
.addAction(R.drawable.cancel_small, "Stempeluhr stoppen!", dismissIntent);



// Gets an instance of the NotificationManager service
NotificationManager notifyMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

// Builds the notification and issues it.
notifyMgr.notify(notificationId, builder.build());
}

public static PendingIntent getDismissIntent(int notificationId, Context context) {



Intent intent = new Intent(context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.putExtra(NOTIFICATION_ID, 4);
PendingIntent dismissIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);


File file = new File(Environment.getExternalStorageDirectory() + "/Arbeitszeit-Kalkulator Daten/Stempeluhr_daten.dat");
if (file.exists()){
file.delete();


}


return dismissIntent;
}
 

Ähnliche Themen

AnnaBauer21
Antworten
0
Aufrufe
484
AnnaBauer21
AnnaBauer21
Zurück
Oben Unten