Mensaje de notificación local
Notificaciones de bajo nivel
- Sin tono/vibración/luz LED
- Mostrar mensajes de notificación solo en la barra de notificaciones
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);
Este bloque de código se muestra en una ventana flotante
Notificación general
- Tono/vibración/luz LED disponibles mediante defaultProperties
- Mostrar el mensaje de notificación en la barra de notificaciones
- Mostrar iconos de notificación en la barra de estado
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);
Este bloque de código se muestra en una ventana flotante
Notificación avanzada
- Tono/vibración/luz LED disponibles mediante defaultProperties
- Mostrar el mensaje de notificación en la barra de notificaciones
- Mostrar iconos de notificación en la barra de estado
- Tras configurar la aplicación para permitir ventanas flotantes, pueden mostrarse en la parte superior de la pantalla
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);
Este bloque de código se muestra en una ventana flotante
Notificación con estilo de texto grande
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);
Este bloque de código se muestra en una ventana flotante
Notificación con estilo de bandeja de entrada
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);
Este bloque de código se muestra en una ventana flotante
Notificación con estilo de imagen grande
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);
Este bloque de código se muestra en una ventana flotante
Notificación de insignia personalizada
- Solo compatible con Huawei/Honor/Xiaomi
- En dispositivos Xiaomi, al eliminar una notificación, el número de insignias se reduce automáticamente en 1
- En dispositivos Huawei/Honor, al eliminar notificaciones, el número de insignias no se reduce automáticamente en 1. Se debe llamar a
MTPushPrivatesApi.setNotificationBadge(context, number)para establecer el número final de insignias
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);
Este bloque de código se muestra en una ventana flotante
Notificación con tono personalizado
- El tono correspondiente debe colocarse previamente en
res/raw; por ejemplo, "coin.mp3"- A partir de Android 8.0, los tonos se configuran en el canal
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);
Este bloque de código se muestra en una ventana flotante
Notificación con canal personalizado
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;
}
Este bloque de código se muestra en una ventana flotante
Notificación con diseño personalizado
// 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);
Este bloque de código se muestra en una ventana flotante
Notificación con redirección personalizada
// 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 redirect 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 redirect 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);
Este bloque de código se muestra en una ventana flotante

