Meine Benachrichtigung ist ein Service (service.java) und was der Dienst tut, ist eine Benachrichtigung über Batterie-Level zu starten, wenn eine Checkbox-Präferenz im Einstellungsbildschirm aktiviert ist .. Was jetzt nicht funktioniert ist die Absicht Geben Sie MainActivity
ein, indem Sie auf die Benachrichtigung klicken. Dies ist der CodeDie Absicht in der Benachrichtigung funktioniert nicht
if(mprefs.getBoolean("notification_a", false)==true){
notificationBuilder = new NotificationCompat.Builder(context);
notificationBuilder.setOngoing(true);
notificationBuilder.setContentTitle("Battery Stats Informations");
notificationBuilder.setContentText("Carica residua: " +level+"%" + " " + "Temperatura: " +temperature+ "°C");
//notificationBuilder.setTicker("Informazioni batteria");
notificationBuilder.setWhen(System.currentTimeMillis());
notificationBuilder.setSmallIcon(R.drawable.icon_small_not);
Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getBroadcast(context, 0, notificationIntent, 0);
notificationBuilder.setContentIntent(contentIntent);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
Notification not=notificationBuilder.build();
mNotificationManager.notify(SIMPLE_NOTIFICATION_ID,not);
} else {
mNotificationManager.cancelAll();
}
Die Absicht Intent notificationIntent = new Intent(context, MainActivity.class
funktioniert nicht. Irgendwelche hilft?
Nun, dann versuche ich .. aber was ist der Unterschied zwischen 'getActivity' und' getBroadcast'? –