Notification unter API 10 - setLatestEventInfo ?

T

txbarth

Ambitioniertes Mitglied
0
Hallo,
ich habe vor ein paar Jahren mal eine App erstellt, unter der ein Service im Vordergrund lief, bis der User die App beendete.

Dabei orientierte ich mich an folgende Beschreibung:
https://developer.android.com/guide/components/services.html
Running a Service in the foreground

Code:
Notification notification = new Notification(R.drawable.icon, getText(R.string.ticker_text),         System.currentTimeMillis());
Intent notificationIntent = new Intent(this, ExampleActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(this, getText(R.string.notification_title),
        getText(R.string.notification_message), pendingIntent);
startForeground(ONGOING_NOTIFICATION_ID, notification);

Notification ist mittlerweile als deprecated gekennzeichnet. Und die Methode setLatestEventInfo existiert gar nicht (mehr). Demnach hätte es so funktionieren dürfen. Trotzdem wird dies aber noch in der Doku angegeben.

Ich mache nun wieder eine App, in der Zwischenzeit hat sich ja viel getan. Notification wird seit API 11 mit dem NotificationCompat.Builder zusammengebaut:

Code:
NotificationCompat.Builder notification = new NotificationCompat.Builder(context);
notification.setSmallIcon(R.drawable.ic_stat_notify);  // the status icon
notification.setTicker(tickerText); // the status text
notification.setWhen(System.currentTimeMillis());  // the time stamp
notification.setContentTitle(contentTitle);  // the label of the entry
notification.setContentText(contentText); // the contents of the entry
notification.setContentIntent(contentIntent); // The intent to send when the entry is clicked
startForeground(R.string.SERVICE_ID, notification.build());

Im Emulator funktioniert es. Aber so hätte ich keine Chance meine App auf meinem alten HTC desire HD mit Android 2.3.5 zu testen. Also, neues Smartphone her und sich nicht mehr mit dem alten Kram beschäftigen? Am Samstag war ich schon im Lade auf der Suche, aber bei der großen Auswahl bekommt man ja eine Krise.

Wird bei euch auch setLatestEventInfo als "Cannot resolve method" angezeigt?
 

Ähnliche Themen

2
Antworten
6
Aufrufe
256
24559
2
B
Antworten
4
Aufrufe
467
bb321
B
Zurück
Oben Unten