Lokale Benachrichtigungsnachricht

Benachrichtigungen mit niedriger Priorität

  • Kein Klingelton/keine Vibration/keine LED-Lampe
  • Benachrichtigungen werden nur in der Benachrichtigungsleiste angezeigt
NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("low_priority_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("Dies ist eine Benachrichtigung mit niedriger Priorität") .setPriority(Notification.PRIORITY_LOW); MTPushPrivatesApi.showNotification(this, notificationMessage);
              
              NotificationMessage notificationMessage = new NotificationMessage()
        .setMessageId("low_priority_" + System.currentTimeMillis())
        .setTitle(this.getApplicationContext().getPackageName())
        .setContent("Dies ist eine Benachrichtigung mit niedriger Priorität")
        .setPriority(Notification.PRIORITY_LOW);
MTPushPrivatesApi.showNotification(this, notificationMessage);

            
Diesen Codeblock im schwebenden Fenster anzeigen

Allgemeine Benachrichtigung

  • Klingelton/Vibration/LED-Lampe über defaultProperties verfügbar
  • Benachrichtigungstext wird in der Benachrichtigungsleiste angezeigt
  • Benachrichtigungssymbole werden in der Statusleiste angezeigt
NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("normal_priority_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("Dies ist eine Benachrichtigung mit normaler Priorität") // Hier wird demonstriert, dass nur Klingelton und Vibration funktionieren .setDefaultProperties(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setPriority(Notification.PRIORITY_DEFAULT); MTPushPrivatesApi.showNotification(this, notificationMessage);
              
              NotificationMessage notificationMessage = new NotificationMessage()
        .setMessageId("normal_priority_" + System.currentTimeMillis())
        .setTitle(this.getApplicationContext().getPackageName())
        .setContent("Dies ist eine Benachrichtigung mit normaler Priorität")
        // Hier wird demonstriert, dass nur Klingelton und Vibration funktionieren
        .setDefaultProperties(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
        .setPriority(Notification.PRIORITY_DEFAULT);
MTPushPrivatesApi.showNotification(this, notificationMessage);

            
Diesen Codeblock im schwebenden Fenster anzeigen

Erweiterte Benachrichtigung

  • Klingelton/Vibration/LED-Lampe über defaultProperties verfügbar
  • Benachrichtigungstext wird in der Benachrichtigungsleiste angezeigt
  • Benachrichtigungssymbole werden in der Statusleiste angezeigt
  • Nach Aktivierung von schwebenden Fenstern in der App kann die Benachrichtigung am oberen Bildschirmrand eingeblendet werden
NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("high_priority_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("Dies ist eine Benachrichtigung mit hoher Priorität") // Hier werden Klingelton/Vibration/LED-Lampe aktiviert .setDefaultProperties(Notification.DEFAULT_ALL) .setPriority(Notification.PRIORITY_HIGH); MTPushPrivatesApi.showNotification(this, notificationMessage);
              
              NotificationMessage notificationMessage = new NotificationMessage()
        .setMessageId("high_priority_" + System.currentTimeMillis())
        .setTitle(this.getApplicationContext().getPackageName())
        .setContent("Dies ist eine Benachrichtigung mit hoher Priorität")
        // Hier werden Klingelton/Vibration/LED-Lampe aktiviert
        .setDefaultProperties(Notification.DEFAULT_ALL)
        .setPriority(Notification.PRIORITY_HIGH);
MTPushPrivatesApi.showNotification(this, notificationMessage);

            
Diesen Codeblock im schwebenden Fenster anzeigen

Benachrichtigung im Großtext-Stil

NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("big_text_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("Dies ist eine Großtext-Benachrichtigung") .setStyle(NotificationMessage.NOTIFICATION_STYLE_BIG_TEXT) .setBigText("„Abschied von Cambridge“ ist ein bekanntes Gedicht des modernen Dichters Xu Zhimo und ein repräsentatives Werk der New Moon School. Mit den wechselnden Gefühlen beim Verlassen von Cambridge als Leitmotiv drückt das gesamte Gedicht die tiefe Verbundenheit mit Cambridge aus. Die Sprache ist leicht und sanft, die Form ausgefeilt und reif. Der Dichter zeichnet mit virtuoser Technik ein fließendes Bild, das überall eine schöne Stimmung erzeugt. Feinfühlig und subtil bringt er seine Liebe zu Kangqiao, seine Nostalgie für das vergangene Leben und seine hilflose Traurigkeit über die Gegenwart zum Ausdruck – ein wahrhaft reiches und bedeutungsvolles Lied in Xu Zhimos Lyrik."); MTPushPrivatesApi.showNotification(this, notificationMessage);
              
              NotificationMessage notificationMessage = new NotificationMessage()
        .setMessageId("big_text_" + System.currentTimeMillis())
        .setTitle(this.getApplicationContext().getPackageName())
        .setContent("Dies ist eine Großtext-Benachrichtigung")
        .setStyle(NotificationMessage.NOTIFICATION_STYLE_BIG_TEXT)
        .setBigText("„Abschied von Cambridge“ ist ein bekanntes Gedicht des modernen Dichters Xu Zhimo und ein repräsentatives Werk der New Moon School. Mit den wechselnden Gefühlen beim Verlassen von Cambridge als Leitmotiv drückt das gesamte Gedicht die tiefe Verbundenheit mit Cambridge aus. Die Sprache ist leicht und sanft, die Form ausgefeilt und reif. Der Dichter zeichnet mit virtuoser Technik ein fließendes Bild, das überall eine schöne Stimmung erzeugt. Feinfühlig und subtil bringt er seine Liebe zu Kangqiao, seine Nostalgie für das vergangene Leben und seine hilflose Traurigkeit über die Gegenwart zum Ausdruck – ein wahrhaft reiches und bedeutungsvolles Lied in Xu Zhimos Lyrik.");
MTPushPrivatesApi.showNotification(this, notificationMessage);

            
Diesen Codeblock im schwebenden Fenster anzeigen

Benachrichtigung im Posteingang-Stil

NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("inbox_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("Dies ist eine Posteingang-Benachrichtigung") .setStyle(MTPushPrivatesApi.NOTIFICATION_STYLE_INBOX) .setInbox(new String[]{"Dies ist Posteingang eins", "Dies ist Posteingang zwei", "Dies ist Posteingang drei"}); MTPushPrivatesApi.showNotification(this, notificationMessage);
              
              NotificationMessage notificationMessage = new NotificationMessage()
        .setMessageId("inbox_" + System.currentTimeMillis())
        .setTitle(this.getApplicationContext().getPackageName())
        .setContent("Dies ist eine Posteingang-Benachrichtigung")
        .setStyle(MTPushPrivatesApi.NOTIFICATION_STYLE_INBOX)
        .setInbox(new String[]{"Dies ist Posteingang eins", "Dies ist Posteingang zwei", "Dies ist Posteingang drei"});
MTPushPrivatesApi.showNotification(this, notificationMessage);

            
Diesen Codeblock im schwebenden Fenster anzeigen

Benachrichtigung im Großbild-Stil

NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("big_picture_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("Dies ist eine Großbild-Benachrichtigung") .setStyle(MTPushPrivatesApi.NOTIFICATION_STYLE_BIG_PICTURE) .setBigPicture("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=96071541,1913562332&fm=26&gp=0.jpg"); MTPushPrivatesApi.showNotification(this, notificationMessage);
              
              NotificationMessage notificationMessage = new NotificationMessage()
        .setMessageId("big_picture_" + System.currentTimeMillis())
        .setTitle(this.getApplicationContext().getPackageName())
        .setContent("Dies ist eine Großbild-Benachrichtigung")
        .setStyle(MTPushPrivatesApi.NOTIFICATION_STYLE_BIG_PICTURE)
        .setBigPicture("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=96071541,1913562332&fm=26&gp=0.jpg");
MTPushPrivatesApi.showNotification(this, notificationMessage);

            
Diesen Codeblock im schwebenden Fenster anzeigen

Benutzerdefinierte Badge-Benachrichtigung (nur für Huawei/Honor/Xiaomi)

  • Wird nur auf Huawei/Honor/XIAOMI unterstützt
  • Auf Xiaomi-Geräten wird beim Löschen einer Benachrichtigung die Anzahl der Badges automatisch um 1 reduziert
  • Auf Huawei/Honor-Geräten wird die Anzahl der Badges beim Löschen nicht automatisch reduziert. Hier muss MTPushPrivatesApi.setNotificationBadge(context, number) aufgerufen werden, um die endgültige Badge-Anzahl festzulegen
NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("badge_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("Dies ist eine Badge-Benachrichtigung") // Kumulative Logik, wobei die Anzahl der Badges um 1 erhöht wird .setBadge(1); MTPushPrivatesApi.showNotification(this, notificationMessage);
              
              NotificationMessage notificationMessage = new NotificationMessage()
        .setMessageId("badge_" + System.currentTimeMillis())
        .setTitle(this.getApplicationContext().getPackageName())
        .setContent("Dies ist eine Badge-Benachrichtigung")
        // Kumulative Logik, wobei die Anzahl der Badges um 1 erhöht wird
        .setBadge(1);
MTPushPrivatesApi.showNotification(this, notificationMessage);

            
Diesen Codeblock im schwebenden Fenster anzeigen

Benachrichtigung mit individuellem Klingelton

  • Der entsprechende Klingelton muss vorab in res/raw/ abgelegt werden, z. B. „coin.mp3“
  • Ab Android 8.0 werden Klingeltöne im Kanal festgelegt
NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("sound_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("Dies ist eine Benachrichtigung mit individuellem Klingelton") .setSound("coin"); MTPushPrivatesApi.showNotification(this, notificationMessage);
              
              NotificationMessage notificationMessage = new NotificationMessage()
        .setMessageId("sound_" + System.currentTimeMillis())
        .setTitle(this.getApplicationContext().getPackageName())
        .setContent("Dies ist eine Benachrichtigung mit individuellem Klingelton")
        .setSound("coin");
MTPushPrivatesApi.showNotification(this, notificationMessage);

            
Diesen Codeblock im schwebenden Fenster anzeigen

Benachrichtigungen mit individuellem Kanal

NotificationChannel notificationChannel = buildChannel(); NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("channel_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("Dies ist eine Kanal-Benachrichtigung") .setChannelId(Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? "" : notificationChannel.getId()); MTPushPrivatesApi.showNotification(this, notificationMessage); // Beispiel: So wird ein Kanal mit normaler Priorität und Klingelton „coin“ erstellt private NotificationChannel buildChannel() { try { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { return null; } NotificationManager notificationManager = (NotificationManager) this.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE); if (notificationManager == null) { return null; } String sound = "coin"; // Kanal-ID String channelId = "money123"; // Kanalname String channelName = "money"; // Kanal-Priorität int importance = NotificationManager.IMPORTANCE_DEFAULT; // Kanalbeschreibung String channelDescription = "Dient zur Demonstration des Kanals mit individuellem Klingelton"; NotificationChannel channel = notificationManager.getNotificationChannel(channelId); if (channel == null) { channel = new NotificationChannel(channelId, channelName, importance); channel.setDescription(channelDescription); channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); Uri soundUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + this.getPackageName() + "/raw/" + sound); channel.setSound(soundUri, Notification.AUDIO_ATTRIBUTES_DEFAULT); notificationManager.createNotificationChannel(channel); } else { Log.d(TAG, "Kanal: [" + channelId + "] existiert bereits"); } return channel; } catch (Throwable throwable) { throwable.printStackTrace(); } return null; }
              
              NotificationChannel notificationChannel = buildChannel();
NotificationMessage notificationMessage = new NotificationMessage()
        .setMessageId("channel_" + System.currentTimeMillis())
        .setTitle(this.getApplicationContext().getPackageName())
        .setContent("Dies ist eine Kanal-Benachrichtigung")
        .setChannelId(Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? "" : notificationChannel.getId());
MTPushPrivatesApi.showNotification(this, notificationMessage);


// Beispiel: So wird ein Kanal mit normaler Priorität und Klingelton „coin“ erstellt
private NotificationChannel buildChannel() {
    try {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
            return null;
        }
        NotificationManager notificationManager = (NotificationManager) this.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
        if (notificationManager == null) {
            return null;
        }
        String sound = "coin";
        // Kanal-ID
        String channelId = "money123";
        // Kanalname
        String channelName = "money";
        // Kanal-Priorität
        int importance = NotificationManager.IMPORTANCE_DEFAULT;
        // Kanalbeschreibung
        String channelDescription = "Dient zur Demonstration des Kanals mit individuellem Klingelton";
        NotificationChannel channel = notificationManager.getNotificationChannel(channelId);
        if (channel == null) {
            channel = new NotificationChannel(channelId, channelName, importance);
            channel.setDescription(channelDescription);
            channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
            Uri soundUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + this.getPackageName() + "/raw/" + sound);
            channel.setSound(soundUri, Notification.AUDIO_ATTRIBUTES_DEFAULT);
            notificationManager.createNotificationChannel(channel);
        } else {
            Log.d(TAG, "Kanal: [" + channelId + "] existiert bereits");
        }
        return channel;
    } catch (Throwable throwable) {
        throwable.printStackTrace();
    }
    return null;
}

            
Diesen Codeblock im schwebenden Fenster anzeigen

Benachrichtigung mit individuellem Layout

// Hier wird eine Konstante definiert, die die builderId des individuellen Layouts darstellt private static final int BUILDER_ID = 1001; // Zuerst das individuelle Layout im Engagelab Private Cloud SDK festlegen NotificationLayout customBuilder = new NotificationLayout() .setLayoutId(R.layout.custom_notification_layout) .setIconViewId(R.id.iv_notification_icon) .setIconResourceId(R.drawable.mtpush_notification_icon) .setTitleViewId(R.id.tv_notification_title) .setContentViewId(R.id.tv_notification_content) .setTimeViewId(R.id.tv_notification_time); MTPushPrivatesApi.setNotificationLayout(this.getApplicationContext(), BUILDER_ID, customBuilder); // Danach individuelle Layout-Benachrichtigung senden NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("custom_layout_" + System.currentTimeMillis()) .setBuilderId(BUILDER_ID) .setTitle(this.getApplicationContext().getPackageName()) .setContent("Dies ist eine Benachrichtigung mit individuellem Layout"); MTPushPrivatesApi.showNotification(this, notificationMessage);
              
              // Hier wird eine Konstante definiert, die die builderId des individuellen Layouts darstellt
private static final int BUILDER_ID = 1001;
// Zuerst das individuelle Layout im Engagelab Private Cloud SDK festlegen
NotificationLayout customBuilder = new NotificationLayout()
        .setLayoutId(R.layout.custom_notification_layout)
        .setIconViewId(R.id.iv_notification_icon)
        .setIconResourceId(R.drawable.mtpush_notification_icon)
        .setTitleViewId(R.id.tv_notification_title)
        .setContentViewId(R.id.tv_notification_content)
        .setTimeViewId(R.id.tv_notification_time);
MTPushPrivatesApi.setNotificationLayout(this.getApplicationContext(), BUILDER_ID, customBuilder);
// Danach individuelle Layout-Benachrichtigung senden
NotificationMessage notificationMessage = new NotificationMessage()
        .setMessageId("custom_layout_" + System.currentTimeMillis())
        .setBuilderId(BUILDER_ID)
        .setTitle(this.getApplicationContext().getPackageName())
        .setContent("Dies ist eine Benachrichtigung mit individuellem Layout");
MTPushPrivatesApi.showNotification(this, notificationMessage);

            
Diesen Codeblock im schwebenden Fenster anzeigen

Benachrichtigung mit individuellem Intent

// Zuerst die intentUri generieren Intent intent = new Intent(); intent.setClassName(this.getPackageName(), IntentActivity.class.getCanonicalName()); intent.setAction(ExampleGlobal.ACTION_INTENT_NOTIFICATION); Bundle bundle = new Bundle(); bundle.putString("description", "Dies ist eine Intent-Benachrichtigung"); bundle.putString("form", MainActivity.class.getSimpleName()); bundle.putString("to", IntentActivity.class.getSimpleName()); intent.putExtras(bundle); String intentUri = intent.toURI(); // Dann individuelle Intent-Benachrichtigung senden NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("intent_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContentText("Dies ist eine Intent-Benachrichtigung") .setContent(intentUri); MTPushPrivatesApi.showNotification(this, notificationMessage);
              
              // Zuerst die intentUri generieren
Intent intent = new Intent();
intent.setClassName(this.getPackageName(), IntentActivity.class.getCanonicalName());
intent.setAction(ExampleGlobal.ACTION_INTENT_NOTIFICATION);
Bundle bundle = new Bundle();
bundle.putString("description", "Dies ist eine Intent-Benachrichtigung");
bundle.putString("form", MainActivity.class.getSimpleName());
bundle.putString("to", IntentActivity.class.getSimpleName());
intent.putExtras(bundle);
String intentUri = intent.toURI();
// Dann individuelle Intent-Benachrichtigung senden
NotificationMessage notificationMessage = new NotificationMessage()
        .setMessageId("intent_" + System.currentTimeMillis())
        .setTitle(this.getApplicationContext().getPackageName())
        .setContentText("Dies ist eine Intent-Benachrichtigung")
        .setContent(intentUri);
MTPushPrivatesApi.showNotification(this, notificationMessage);

            
Diesen Codeblock im schwebenden Fenster anzeigen
icon
Vertrieb kontaktieren