Notification über widget anzeigen und enternen

kukuk

kukuk

App-Anbieter (kostenlos)
29
Hallo, ich erstelle eine Notification und kann diese auch wieder entfernen. Das Funktioniert über eine Activity ohne Probleme.

Jetzt habe ich aber auch ein Widget und brauche Hilfe wie ich dort auch dort die Notification anzeigen lassen kann?

Kann mir da jemand helfen?

Code:
public void notification_erstellen(){
	
		NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
		NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);

		mBuilder.setContentTitle("Überstunden Stempeluhr")
		        .setContentText("Stempeluhr gestartet")
		 
		        
		        .setSmallIcon(R.drawable.main_icon);

		PendingIntent in = PendingIntent.getActivity(getApplicationContext(), 0, getIntent(), 0);
		mBuilder.setContentIntent(in);

		mNotificationManager.notify(FM_NOTIFICATION_ID, mBuilder.build());
	}
	public void notification_erstellen(StempeluhrActivity handle){
		handle.notification_erstellen();

	}
	
	public void notification_entfernen(){
		try{
			NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
			NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
			NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);  
			    manager.cancel(FM_NOTIFICATION_ID);
		}catch (Exception e){
			
		}
	}







Ich habe jetzt schon folgendes im Widget Probiert aber das Funktioniert leider nicht:
Code:
		String context;
		LocationManager locationManager;
		context = Context.LOCATION_SERVICE;
		locationManager = (LocationManager) Config.context.getSystemService(context);
		
		
		NotificationManager mNotificationManager = (NotificationManager)  Config.context.getSystemService(Context.NOTIFICATION_SERVICE);
		NotificationCompat.Builder mBuilder = new NotificationCompat.Builder((Context) Config.context.getSystemService(context));

		mBuilder.setContentTitle("Überstunden Stempeluhr")
		        .setContentText("Stempeluhr gestartet")
		 
		        
		        .setSmallIcon(R.drawable.main_icon);

		PendingIntent in = PendingIntent.getActivity( (Context) Config.context.getSystemService(context), 0, Config.context.getIntent(), 0);
		mBuilder.setContentIntent(in);

		mNotificationManager.notify(FM_NOTIFICATION_ID, mBuilder.build());

Und in der Activity habe ich Config.context = this; und in der Config.java public static StempeluhrActivity context = null;
 
Zuletzt bearbeitet:

Ähnliche Themen

wernho
Antworten
11
Aufrufe
679
wernho
wernho
D
  • Data2006
3 4 5
Antworten
84
Aufrufe
3.644
jogimuc
J
M
  • MikelKatzengreis
Antworten
5
Aufrufe
116
swa00
swa00
Zurück
Oben Unten