2017-07-17 4 views
1

ich versucht, dies zu tun:nicht veraltet Weise eine Benachrichtigung angezeigt werden in android

Notification not = new Notification(idIcon, text, System.currentTimeMillis()); 
PendingIntent pInt = PendingIntent.getActivity(ctx, 0, new Intent(ctx, the_class_to_call), 0); 

not.setLatestEventInfo(ctx, app_name, text, pInt); 

Aber diese aufgegeben.

ich versucht, dies zu tun:

NotificationCompat.Builder mBuilder = 
      new NotificationCompat.Builder(this) 
        .setSmallIcon(R.drawable.app_logo) 
        .setContentTitle("My notification") 
        .setContentText("Hello World!"); 

Aber das war auch veraltet.

Nun, was ist die nicht veraltete Möglichkeit, eine Benachrichtigung in Android anzuzeigen? Alle Antworten, die ich finde, sind diese zwei Wege.

Meine minSdkVersion: 19

Antwort

0

Endlich finde ich eine Lösung für dieses Problem.

Ich verwende eine Kompatibilitätsbibliothek. Ich benutze appcompat v7.

appcompat v7 hat eine Aktualisierung für NotificationCompat.Builder. Aber, wenn ich versuche, dies zu tun:

NotificationCompat.Builder mBuilder = 
     new NotificationCompat.Builder(this) 
       .setSmallIcon(R.drawable.app_logo) 
       .setContentTitle("My notification") 
       .setContentText("Hello World!"); 

Der Compiler interpretiere ich bin mit einem appcompat v4 Builder.

Ich repariere es eine Umwandlung in appcompat v7 Builder zu tun.

NotificationCompat.Builder mBuilder = 
      (NotificationCompat.Builder) new NotificationCompat.Builder(this) 
        .setSmallIcon(R.drawable.app_logo) 
        .setContentTitle("My notification") 
        .setContentText("Hello World!"); 
Verwandte Themen