logoDokumen
Cari

Pesan Notifikasi Lokal

Notifikasi Prioritas Rendah

  • Tanpa nada dering/getaran/lampu LED
  • Hanya menampilkan pesan notifikasi di bilah notifikasi
NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("low_priority_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("ini adalah notifikasi prioritas rendah") .setPriority(Notification.PRIORITY_LOW); MTPushPrivatesApi.showNotification(this, notificationMessage);
              
              NotificationMessage notificationMessage = new NotificationMessage()
        .setMessageId("low_priority_" + System.currentTimeMillis())
        .setTitle(this.getApplicationContext().getPackageName())
        .setContent("ini adalah notifikasi prioritas rendah")
        .setPriority(Notification.PRIORITY_LOW);
MTPushPrivatesApi.showNotification(this, notificationMessage);

            
Tampilkan blok kode ini di jendela mengambang

Notifikasi Umum

  • Nada dering/Getaran/lampu LED tersedia melalui defaultProperties
  • Menampilkan pesan notifikasi di bilah notifikasi
  • Menampilkan ikon notifikasi di status bar
NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("normal_priority_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("ini adalah notifikasi prioritas normal") // Contoh: hanya nada dering dan getaran yang aktif .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("ini adalah notifikasi prioritas normal")
        // Contoh: hanya nada dering dan getaran yang aktif
        .setDefaultProperties(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
        .setPriority(Notification.PRIORITY_DEFAULT);
MTPushPrivatesApi.showNotification(this, notificationMessage);

            
Tampilkan blok kode ini di jendela mengambang

Notifikasi Prioritas Tinggi

  • Nada dering/Getaran/lampu LED tersedia melalui defaultProperties
  • Menampilkan pesan notifikasi di bilah notifikasi
  • Menampilkan ikon notifikasi di status bar
  • Jika aplikasi diizinkan menampilkan jendela mengambang, notifikasi bisa muncul di bagian atas layar
NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("high_priority_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("ini adalah notifikasi prioritas tinggi") .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("ini adalah notifikasi prioritas tinggi")
        .setDefaultProperties(Notification.DEFAULT_ALL)
        .setPriority(Notification.PRIORITY_HIGH);
MTPushPrivatesApi.showNotification(this, notificationMessage);

            
Tampilkan blok kode ini di jendela mengambang

Notifikasi Gaya Teks Besar

NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("big_text_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("ini adalah notifikasi teks besar") .setStyle(NotificationMessage.NOTIFICATION_STYLE_BIG_TEXT) .setBigText("Perpisahan di Cambridge adalah puisi terkenal karya penyair modern Xu Zhimo dan merupakan karya representatif dari Sekolah Bulan Baru. Dengan naik turunnya perasaan saat meninggalkan Cambridge sebagai benang merah, seluruh puisi ini mengekspresikan perasaan mendalam bergantung pada Cambridge karena alasan lain. Bahasa yang ringan dan lembut, bentuk yang indah dan matang, penyair menggambarkan sebuah gambar yang mengalir dengan metode virtual dan nyata, yang menciptakan suasana indah di mana-mana. Ia dengan hati-hati dan halus mengekspresikan cinta penyair pada Kangqiao, kerinduannya pada kehidupan masa lalu dan kesedihan tak berdaya untuk saat ini, yang merupakan nyanyian sejati, kaya, dan bermakna dalam puisi Xu Zhimo."); MTPushPrivatesApi.showNotification(this, notificationMessage);
              
              NotificationMessage notificationMessage = new NotificationMessage()
        .setMessageId("big_text_" + System.currentTimeMillis())
        .setTitle(this.getApplicationContext().getPackageName())
        .setContent("ini adalah notifikasi teks besar")
        .setStyle(NotificationMessage.NOTIFICATION_STYLE_BIG_TEXT)
        .setBigText("Perpisahan di Cambridge adalah puisi terkenal karya penyair modern Xu Zhimo dan merupakan karya representatif dari Sekolah Bulan Baru. Dengan naik turunnya perasaan saat meninggalkan Cambridge sebagai benang merah, seluruh puisi ini mengekspresikan perasaan mendalam bergantung pada Cambridge karena alasan lain. Bahasa yang ringan dan lembut, bentuk yang indah dan matang, penyair menggambarkan sebuah gambar yang mengalir dengan metode virtual dan nyata, yang menciptakan suasana indah di mana-mana. Ia dengan hati-hati dan halus mengekspresikan cinta penyair pada Kangqiao, kerinduannya pada kehidupan masa lalu dan kesedihan tak berdaya untuk saat ini, yang merupakan nyanyian sejati, kaya, dan bermakna dalam puisi Xu Zhimo.");
MTPushPrivatesApi.showNotification(this, notificationMessage);

            
Tampilkan blok kode ini di jendela mengambang

Notifikasi Gaya Kotak Masuk

NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("inbox_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("ini adalah notifikasi kotak masuk") .setStyle(MTPushPrivatesApi.NOTIFICATION_STYLE_INBOX) .setInbox(new String[]{"ini kotak masuk satu", "ini kotak masuk dua", "ini kotak masuk tiga"}); MTPushPrivatesApi.showNotification(this, notificationMessage);
              
              NotificationMessage notificationMessage = new NotificationMessage()
        .setMessageId("inbox_" + System.currentTimeMillis())
        .setTitle(this.getApplicationContext().getPackageName())
        .setContent("ini adalah notifikasi kotak masuk")
        .setStyle(MTPushPrivatesApi.NOTIFICATION_STYLE_INBOX)
        .setInbox(new String[]{"ini kotak masuk satu", "ini kotak masuk dua", "ini kotak masuk tiga"});
MTPushPrivatesApi.showNotification(this, notificationMessage);

            
Tampilkan blok kode ini di jendela mengambang

Notifikasi Gaya Gambar Besar

NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("big_picture_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("ini adalah notifikasi gambar besar") .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("ini adalah notifikasi gambar besar")
        .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);

            
Tampilkan blok kode ini di jendela mengambang

Notifikasi Custom Badge

  • Hanya didukung di Huawei/Honor/XIAOMI
  • Pada Xiaomi, saat notifikasi dihapus, jumlah badge otomatis berkurang 1
  • Pada Huawei/Honor, saat notifikasi dihapus, jumlah badge tidak otomatis berkurang 1. Perlu memanggil MTPushPrivatesApi.setNotificationBadge(context, jumlah) untuk mengatur badge akhir
NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("badge_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("ini adalah notifikasi badge") // Logika akumulasi, badge +1 .setBadge(1); MTPushPrivatesApi.showNotification(this, notificationMessage);
              
              NotificationMessage notificationMessage = new NotificationMessage()
        .setMessageId("badge_" + System.currentTimeMillis())
        .setTitle(this.getApplicationContext().getPackageName())
        .setContent("ini adalah notifikasi badge")
        // Logika akumulasi, badge +1
        .setBadge(1);
MTPushPrivatesApi.showNotification(this, notificationMessage);

            
Tampilkan blok kode ini di jendela mengambang

Notifikasi Nada Dering Kustom

  • File nada dering harus diletakkan di res/raw/, misal "coin.mp3"
  • Mulai Android 8.0, nada dering diatur di channel
NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("sound_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("ini adalah notifikasi suara") .setSound("coin"); MTPushPrivatesApi.showNotification(this, notificationMessage);
              
              NotificationMessage notificationMessage = new NotificationMessage()
        .setMessageId("sound_" + System.currentTimeMillis())
        .setTitle(this.getApplicationContext().getPackageName())
        .setContent("ini adalah notifikasi suara")
        .setSound("coin");
MTPushPrivatesApi.showNotification(this, notificationMessage);

            
Tampilkan blok kode ini di jendela mengambang

Notifikasi Channel Kustom

NotificationChannel notificationChannel = buildChannel(); NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("channel_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContent("ini adalah notifikasi channel") .setChannelId(Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? "" : notificationChannel.getId()); MTPushPrivatesApi.showNotification(this, notificationMessage); // Contoh membuat channel dengan level normal dan nada dering 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"; String channelId = "money123"; String channelName = "money"; int importance = NotificationManager.IMPORTANCE_DEFAULT; String channelDescription = "Digunakan untuk mendemonstrasikan channel, dengan nada dering kustom"; 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 + "] sudah ada"); } 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("ini adalah notifikasi channel")
        .setChannelId(Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? "" : notificationChannel.getId());
MTPushPrivatesApi.showNotification(this, notificationMessage);

// Contoh membuat channel dengan level normal dan nada dering 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";
        String channelId = "money123";
        String channelName = "money";
        int importance = NotificationManager.IMPORTANCE_DEFAULT;
        String channelDescription = "Digunakan untuk mendemonstrasikan channel, dengan nada dering kustom";
        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 + "] sudah ada");
        }
        return channel;
    } catch (Throwable throwable) {
        throwable.printStackTrace();
    }
    return null;
}

            
Tampilkan blok kode ini di jendela mengambang

Notifikasi Tata Letak Kustom

private static final int BUILDER_ID = 1001; // Atur tata letak kustom ke SDK private cloud Engagelab 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); // Kirim notifikasi tata letak kustom NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("custom_layout_" + System.currentTimeMillis()) .setBuilderId(BUILDER_ID) .setTitle(this.getApplicationContext().getPackageName()) .setContent("ini adalah notifikasi tata letak kustom"); MTPushPrivatesApi.showNotification(this, notificationMessage);
              
              private static final int BUILDER_ID = 1001;
// Atur tata letak kustom ke SDK private cloud Engagelab
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);
// Kirim notifikasi tata letak kustom
NotificationMessage notificationMessage = new NotificationMessage()
        .setMessageId("custom_layout_" + System.currentTimeMillis())
        .setBuilderId(BUILDER_ID)
        .setTitle(this.getApplicationContext().getPackageName())
        .setContent("ini adalah notifikasi tata letak kustom");
MTPushPrivatesApi.showNotification(this, notificationMessage);

            
Tampilkan blok kode ini di jendela mengambang

Notifikasi Custom Intent

Intent intent = new Intent(); intent.setClassName(this.getPackageName(), IntentActivity.class.getCanonicalName()); intent.setAction(ExampleGlobal.ACTION_INTENT_NOTIFICATION); Bundle bundle = new Bundle(); bundle.putString("description", "ini adalah notifikasi intent"); bundle.putString("form", MainActivity.class.getSimpleName()); bundle.putString("to", IntentActivity.class.getSimpleName()); intent.putExtras(bundle); String intentUri = intent.toURI(); // Kirim notifikasi custom intent NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("intent_" + System.currentTimeMillis()) .setTitle(this.getApplicationContext().getPackageName()) .setContentText("ini adalah notifikasi intent") .setContent(intentUri); MTPushPrivatesApi.showNotification(this, notificationMessage);
              
              Intent intent = new Intent();
intent.setClassName(this.getPackageName(), IntentActivity.class.getCanonicalName());
intent.setAction(ExampleGlobal.ACTION_INTENT_NOTIFICATION);
Bundle bundle = new Bundle();
bundle.putString("description", "ini adalah notifikasi intent");
bundle.putString("form", MainActivity.class.getSimpleName());
bundle.putString("to", IntentActivity.class.getSimpleName());
intent.putExtras(bundle);
String intentUri = intent.toURI();
// Kirim notifikasi custom intent
NotificationMessage notificationMessage = new NotificationMessage()
        .setMessageId("intent_" + System.currentTimeMillis())
        .setTitle(this.getApplicationContext().getPackageName())
        .setContentText("ini adalah notifikasi intent")
        .setContent(intentUri);
MTPushPrivatesApi.showNotification(this, notificationMessage);

            
Tampilkan blok kode ini di jendela mengambang
icon
Hubungi Sales