Local Notification Message

อัพเดทล่าสุด :2022-11-22

Low level notifications

  • No ringtone/vibration/led light
  • Show notification messages only in the notification bar
NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("low_priority_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("this is a low priority notification") .setPriority(Notification.PRIORITY_LOW); MTPushPrivatesApi.showNotification(this, notificationMessage);
                  NotificationMessage notificationMessage = new NotificationMessage()
                .setMessageId("low_priority_" + System.currentTimeMillis())
                .setTitle(this.getApplicationContext().getPackageName())
                .setContent("this is a low priority notification")
                .setPriority(Notification.PRIORITY_LOW);
        MTPushPrivatesApi.showNotification(this, notificationMessage);

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

General Notification

  • Ringtone/Vibration/led lamp available via defaultProperties
  • Show notification message in notification bar
  • Show notification icons in the status bar
NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("normal_priority_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("this is a normal priority notification") // Here's a demonstration that only ringtones and vibrations work .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("this is a normal priority notification")
                // Here's a demonstration that only ringtones and vibrations work
                .setDefaultProperties(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
                .setPriority(Notification.PRIORITY_DEFAULT);
        MTPushPrivatesApi.showNotification(this, notificationMessage);

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

Advanced Notification

  • Ringtone/Vibration/led lamp available via defaultProperties
  • Show notification message in notification bar
  • Show notification icons in the status bar
  • After setting the application to allow floating windows, they can pop up at the top of the screen
NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("high_priority_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("this is a high priority notification") // Here's how the ringtone/vibration/led light works .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("this is a high priority notification")
                // Here's how the ringtone/vibration/led light works
                .setDefaultProperties(Notification.DEFAULT_ALL)
                .setPriority(Notification.PRIORITY_HIGH);
        MTPushPrivatesApi.showNotification(this, notificationMessage);

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

Large Text Style Notification

NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("big_text_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("this is a big text notification") .setStyle(NotificationMessage.NOTIFICATION_STYLE_BIG_TEXT) .setBigText("Farewell to Cambridge is a well-known poem by modern poet Xu Zhimo and a representative work of the New Moon School. With the ups and downs of feeling when leaving Cambridge as a clue, the whole poem expresses the deep feeling of relying on Cambridge for other reasons. Lightweight and soft language, exquisite and mature form, the poet portrays a flowing picture with the method of virtual and real, which constitutes a beautiful mood everywhere. He carefully and subtly expresses the poet's love for Kangqiao, his nostalgia for the past life and his helpless sorrow for the present, which is a true, rich and meaningful singing in Xu Zhimo's poems."); MTPushPrivatesApi.showNotification(this, notificationMessage);
                  NotificationMessage notificationMessage = new NotificationMessage()
                .setMessageId("big_text_" + System.currentTimeMillis())
                .setTitle(this.getApplicationContext().getPackageName())
                .setContent("this is a big text notification")
                .setStyle(NotificationMessage.NOTIFICATION_STYLE_BIG_TEXT)
                .setBigText("Farewell to Cambridge is a well-known poem by modern poet Xu Zhimo and a representative work of the New Moon School. With the ups and downs of feeling when leaving Cambridge as a clue, the whole poem expresses the deep feeling of relying on Cambridge for other reasons. Lightweight and soft language, exquisite and mature form, the poet portrays a flowing picture with the method of virtual and real, which constitutes a beautiful mood everywhere. He carefully and subtly expresses the poet's love for Kangqiao, his nostalgia for the past life and his helpless sorrow for the present, which is a true, rich and meaningful singing in Xu Zhimo's poems.");
        MTPushPrivatesApi.showNotification(this, notificationMessage);

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

Inbox Style Notification

NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("inbox_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("this is a inbox notification") .setStyle(MTPushPrivatesApi.NOTIFICATION_STYLE_INBOX) .setInbox(new String[]{"this is inbox one", "this is inbox two", "this is inbox three"}); MTPushPrivatesApi.showNotification(this, notificationMessage);
                  NotificationMessage notificationMessage = new NotificationMessage()
                .setMessageId("inbox_" + System.currentTimeMillis())
                .setTitle(this.getApplicationContext().getPackageName())
                .setContent("this is a inbox notification")
                .setStyle(MTPushPrivatesApi.NOTIFICATION_STYLE_INBOX)
                .setInbox(new String[]{"this is inbox one", "this is inbox two", "this is inbox three"});
        MTPushPrivatesApi.showNotification(this, notificationMessage);

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

Large Picture Style Notification

NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("big_picture_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("this is a big picture notification") .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("this is a big picture notification")
                .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);

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

Custom Corner Notification

  • Only support Huawei/Glory/XIAOMI
  • On millet device, delete notification, the number of corner labels is automatically reduced by 1
  • On Huawei/Glory devices, delete notifications, the number of corners will not be automatically reduced by 1. MTPushPrivatesApi.setNotificationBadge (context, number) needs to be called to set the final number of corners
NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("badge_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("this is a badge notification") // Cumulative logic, where the number of corners + 1 .setBadge(1); MTPushPrivatesApi.showNotification(this, notificationMessage);
                  NotificationMessage notificationMessage = new NotificationMessage()
                .setMessageId("badge_" + System.currentTimeMillis())
                .setTitle(this.getApplicationContext().getPackageName())
                .setContent("this is a badge notification")
                // Cumulative logic, where the number of corners + 1
                .setBadge(1);
        MTPushPrivatesApi.showNotification(this, notificationMessage);

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

Custom ringtone notification

  • The corresponding ringtone needs to be placed in res/raw/ahead of time, for example, "coin.mp3"
  • Android 8.0 starts, ringtones are set in channel
NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("sound_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("this is a sound notification") .setSound("coin"); MTPushPrivatesApi.showNotification(this, notificationMessage);
                  NotificationMessage notificationMessage = new NotificationMessage()
                .setMessageId("sound_" + System.currentTimeMillis())
                .setTitle(this.getApplicationContext().getPackageName())
                .setContent("this is a sound notification")
                .setSound("coin");
        MTPushPrivatesApi.showNotification(this, notificationMessage);

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

Custom channel notifications

NotificationChannel notificationChannel = buildChannel(); NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("channel_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("this is a channel notification") .setChannelId(Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? "" : notificationChannel.getId()); MTPushPrivatesApi.showNotification(this, notificationMessage); // Demonstrate how to create a channel of normal level with a ring tone coin 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"; // channel id String channelId = "money123"; // channel name String channelName = "money"; // Channel priority int importance = NotificationManager.IMPORTANCE_DEFAULT; // channel description String channelDescription = "Used to demonstrate the channel, with customized ringtones"; 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, "channel: [" + channelId + "] is already exists"); } 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("this is a channel notification")
                .setChannelId(Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? "" : notificationChannel.getId());
        MTPushPrivatesApi.showNotification(this, notificationMessage);
    
    
    // Demonstrate how to create a channel of normal level with a ring tone coin
    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";
            // channel id
            String channelId = "money123";
            // channel name
            String channelName = "money";
            // Channel priority
            int importance = NotificationManager.IMPORTANCE_DEFAULT;
            // channel description
            String channelDescription = "Used to demonstrate the channel, with customized ringtones";
            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, "channel: [" + channelId + "] is already exists");
            }
            return channel;
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return null;
    }

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

Custom Layout Notification

// A constant is defined here, representing the builderId of the custom layout private static final int BUILDER_ID = 1001; // First set the custom layout to the Engagelab private cloud SDK 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); // Send custom layout notification later NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("custom_layout_" + System.currentTimeMillis()) .setBuilderId(BUILDER_ID) .setTitle(this.getApplicationContext().getPackageName()) .setContent("this is a custom layout notification"); MTPushPrivatesApi.showNotification(this, notificationMessage);
                  // A constant is defined here, representing the builderId of the custom layout
        private static final int BUILDER_ID = 1001;
        // First set the custom layout to the Engagelab private cloud SDK
        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);
        // Send custom layout notification later
        NotificationMessage notificationMessage = new NotificationMessage()
                .setMessageId("custom_layout_" + System.currentTimeMillis())
                .setBuilderId(BUILDER_ID)
                .setTitle(this.getApplicationContext().getPackageName())
                .setContent("this is a custom layout notification");
        MTPushPrivatesApi.showNotification(this, notificationMessage);

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

Custom Jump Notification

// First get the intentUri Intent intent = new Intent(); intent.setClassName(this.getPackageName(), IntentActivity.class.getCanonicalName()); intent.setAction(ExampleGlobal.ACTION_INTENT_NOTIFICATION); Bundle bundle = new Bundle(); bundle.putString("description", "this is a intent notification"); bundle.putString("form", MainActivity.class.getSimpleName()); bundle.putString("to", IntentActivity.class.getSimpleName()); intent.putExtras(bundle); String intentUri = intent.toURI(); // Then send a custom jump notification NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("intent_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContentText("this is a intent notification") .setContent(intentUri); MTPushPrivatesApi.showNotification(this, notificationMessage);
                  // First get the intentUri
        Intent intent = new Intent();
        intent.setClassName(this.getPackageName(), IntentActivity.class.getCanonicalName());
        intent.setAction(ExampleGlobal.ACTION_INTENT_NOTIFICATION);
        Bundle bundle = new Bundle();
        bundle.putString("description", "this is a intent notification");
        bundle.putString("form", MainActivity.class.getSimpleName());
        bundle.putString("to", IntentActivity.class.getSimpleName());
        intent.putExtras(bundle);
        String intentUri = intent.toURI();
                // Then send a custom jump notification
        NotificationMessage notificationMessage = new NotificationMessage()
                .setMessageId("intent_" + System.currentTimeMillis())
                .setTitle(this.getApplicationContext().getPackageName())
                .setContentText("this is a intent notification")
                .setContent(intentUri);
        MTPushPrivatesApi.showNotification(this, notificationMessage);

        
โค้ดนี้โชว์เป็นหน้าต่างลอย
在文档中心打开
icon
Contact Sales