Custom Notification

  • Antworten:3
Gelöschter Account
  • Forum-Beiträge: 35

20.10.2012, 21:08:44 via Website

Hallo Freunde.
in meiner App erstelle die die Notification mitm folgendem Code:
1NotificationManager notificationManager = (NotificationManager)
2 getSystemService(ctx.NOTIFICATION_SERVICE);
3 Notification notification = new Notification(
4 R.drawable.ic_launcher,
5 titel, System.currentTimeMillis());
6 notification.flags |= Notification.FLAG_AUTO_CANCEL;
7 notification.number = count;
8 PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
9 new Intent(), 0);
10 notification.setLatestEventInfo(ctx, titelon, nmessages
11 + anzahl1 + " " + norders + anzahl + " " + titeloff + anzahl2,
12 pendingIntent);
13 notificationManager.notify(0, notification);
es funktionier alles schön und gut
nur wenn ich die bischn längere Texte einsetze dann sind die nicht vollständig sichtbar und die Notification immer einzeilig bleibt.
Konnte man da eine benutzerdefinierte Notification schreiben ? (ich habe in der Doku gesehen dass es geht, nur blöd ist, ich entwickle die App für android 2.1 und die Funktionen die in der Doku drin sind, sind bei dem minsdk dann nicht vorhanden).
Ist das was ich vorhabe überhaupt möglich ???

Antworten
Gelöschter Account
  • Forum-Beiträge: 29

20.10.2012, 23:06:52 via App

hallo sergej, du kannst einene eigene view erzeugen und diese einfügen mit allem was du willst...
mfg samuel

Antworten
Gelöschter Account
  • Forum-Beiträge: 35

20.10.2012, 23:13:17 via Website

tschuldigung, kenne mich mit notifications noch nicht so gut aus. Wo soll ich das erstellte Layout setzen im Notification Manager oder in Notification ?

Antworten
Gelöschter Account
  • Forum-Beiträge: 29

25.10.2012, 23:20:33 via Website

Ich hoffe dieses beispiel hilft:

1NotificationManager nm = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
2Notification noti = new Notification(deinIcon, "Title", System.currentTimeMillis());
3
4RemoteViews contentView = new RemoteViews(this.getPackageName(), R.layout.noti); // Hier lädst du das layout aus dem .xml file
5
6contentView.setImageViewBitmap(R.id.status_icon, bitmap); //und hier kannst du das layout noch verändern:
7contentView.setTextViewText(R.id.status_title, "Some Text"); // die ids müssen natürlich
8contentView.setTextViewText(R.id.status_text, "More Text"); // im layout vorhanden sein
9
10noti.contentView = contentView;
11nm.notify(ID, noti);

und im noti.xml:

1<?xml version="1.0" encoding="utf-8"?>
2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="fill_parent"
4 android:layout_height="fill_parent"
5 android:padding="5dp" >
6
7 <ImageView
8 android:id="@+id/status_icon"
9 android:layout_width="40dp"
10 android:layout_height="fill_parent"
11 android:layout_marginRight="10dp" />
12
13 <LinearLayout
14 android:layout_width="wrap_content"
15 android:layout_height="match_parent"
16 android:orientation="vertical" >
17
18 <TextView
19 android:id="@+id/status_title"
20 android:layout_width="wrap_content"
21 android:layout_height="wrap_content"
22 android:text="Large Text"
23 android:textAppearance="?android:attr/textAppearanceMedium" />
24
25 <TextView
26 android:id="@+id/status_text"
27 android:layout_width="wrap_content"
28 android:layout_height="wrap_content"
29 android:lines="1"
30 android:text="Text" />
31
32 </LinearLayout>
33</LinearLayout>

mfg Samuel

Antworten