foxylion
Fortgeschrittenes Mitglied
- 10
Hallo,
ich hab eine Notification mit eigenem Layout und würde jetzt gerne die Notification immer mal wieder abändern, ohne sie zu löschen und neu zu erstellen. Wie mach ich das? Alle versuche den Text zu ändern sind bis jetzt daran gescheitert, das die Anzeige der Notification nicht aktualisiert wird.
Code:
Layout:
Gestartet wird das ganze, indem Man ein Objekt der Klasse anlegt und die Acitivity die dazugehört mitgibt.
setText ändert aber leider nicht den Text der Notification.
Jemand ne Idee?
Grüße & Danke schon mal
foxyyy
ich hab eine Notification mit eigenem Layout und würde jetzt gerne die Notification immer mal wieder abändern, ohne sie zu löschen und neu zu erstellen. Wie mach ich das? Alle versuche den Text zu ändern sind bis jetzt daran gescheitert, das die Anzeige der Notification nicht aktualisiert wird.
Code:
Code:
package de.foxylion.android.test;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;
public class PermanentNotification {
private static String uniqueText = "string";
private static int uniqueId = 1473513389;
private Activity activity;
private NotificationManager mManager;
private Notification notification;
private RemoteViews contentView;
public PermanentNotification(Activity activity) {
this.activity = activity;
mManager = (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE);
}
public void show() {
NotificationManager mManager = (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE);
notification = new Notification(R.drawable.icon,
activity.getString(R.string.app_name),
System.currentTimeMillis());
contentView = new RemoteViews(activity.getPackageName(), R.layout.permanent_notification);
setText(activity.getString(R.string.app_loading));
notification.contentView = contentView;
Intent notificationIntent = new Intent(activity, activity.getClass());
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
PendingIntent contentIntent = PendingIntent.getActivity(activity, 0, notificationIntent, 0);
notification.contentIntent = contentIntent;
notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
mManager.notify(uniqueText, uniqueId, notification);
}
public void hide() {
mManager.cancel(uniqueText, uniqueId);
}
public void setText(String text) {
contentView.setTextViewText(R.id.PermanentNotification_Text, text);
}
}
Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView android:id="@+id/PermanentNotification_Image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:src="@drawable/icon"
/>
<TextView android:id="@+id/PermanentNotification_Heading"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="65dp"
android:layout_marginTop="6dp"
android:textColor="#555555"
android:textStyle="bold"
android:text="@string/app_name"
/>
<TextView android:id="@+id/PermanentNotification_Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="65dp"
android:layout_marginTop="20dp"
android:textColor="#000000"
/>
</RelativeLayout>
setText ändert aber leider nicht den Text der Notification.
Jemand ne Idee?
Grüße & Danke schon mal
foxyyy
Zuletzt bearbeitet: