ローカル通知メッセージ
低レベル通知
- 着信音/バイブレーション/LEDライトなし
- 通知バーにのみ通知メッセージを表示
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);
このコードブロックはフローティングウィンドウ内に表示されます
一般通知
- defaultPropertiesを介して着信音/バイブレーション/LEDランプを使用可能
- 通知バーに通知メッセージを表示
- ステータスバーに通知アイコンを表示
NotificationMessage notificationMessage = new NotificationMessage()
.setMessageId("normal_priority_" + System.currentTimeMillis())
.setTitle(this.getApplicationContext().getPackageName())
.setContent("this is a normal priority notification")
// 着信音とバイブレーションのみが機能する例を示します
.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")
// 着信音とバイブレーションのみが機能する例を示します
.setDefaultProperties(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
.setPriority(Notification.PRIORITY_DEFAULT);
MTPushPrivatesApi.showNotification(this, notificationMessage);
このコードブロックはフローティングウィンドウ内に表示されます
高度な通知
- defaultPropertiesを介して着信音/バイブレーション/LEDランプを使用可能
- 通知バーに通知メッセージを表示
- ステータスバーに通知アイコンを表示
- アプリケーションがフローティングウィンドウを許可するように設定した後、画面の上部にポップアップできます
NotificationMessage notificationMessage = new NotificationMessage()
.setMessageId("high_priority_" + System.currentTimeMillis())
.setTitle(this.getApplicationContext().getPackageName())
.setContent("this is a high priority notification")
// 着信音/バイブレーション/LEDライトの機能の例
.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")
// 着信音/バイブレーション/LEDライトの機能の例
.setDefaultProperties(Notification.DEFAULT_ALL)
.setPriority(Notification.PRIORITY_HIGH);
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("《再别康桥》は現代詩人徐志摩による有名な詩で、新月派の代表的な作品です。ケンブリッジを離れるときの感情の起伏を手がかりに、詩全体はケンブリッジへの深い愛着を表現しています。軽やかで柔らかい言葉遣い、精巧で成熟した形式の中で、詩人は虚実の手法で流れる絵を描き出し、至る所に美しいムードを構成しています。詩人はケンブリッジへの愛情、過去の生活への郷愁、そして現在への無力な悲しみを細やかに表現しており、徐志摩の詩の中でも真摯で豊かな意味を持つ歌唱です。");
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("《再别康桥》は現代詩人徐志摩による有名な詩で、新月派の代表的な作品です。ケンブリッジを離れるときの感情の起伏を手がかりに、詩全体はケンブリッジへの深い愛着を表現しています。軽やかで柔らかい言葉遣い、精巧で成熟した形式の中で、詩人は虚実の手法で流れる絵を描き出し、至る所に美しいムードを構成しています。詩人はケンブリッジへの愛情、過去の生活への郷愁、そして現在への無力な悲しみを細やかに表現しており、徐志摩の詩の中でも真摯で豊かな意味を持つ歌唱です。");
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);
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("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);
このコードブロックはフローティングウィンドウ内に表示されます
カスタムコーナー通知
- 華為/Glory/XIAOMIのみサポート
- 小米デバイスでは、通知を削除すると、コーナーラベルの数が自動的に1つ減少します
- 華為/Gloryデバイスでは、通知を削除しても、コーナーの数は自動的に1つ減少しません。MTPushPrivatesApi.setNotificationBadge(context, number)を呼び出して、最終的なコーナーの数を設定する必要があります
NotificationMessage notificationMessage = new NotificationMessage()
.setMessageId("badge_" + System.currentTimeMillis())
.setTitle(this.getApplicationContext().getPackageName())
.setContent("this is a badge notification")
// 累積ロジック。コーナーの数が+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")
// 累積ロジック。コーナーの数が+1されます
.setBadge(1);
MTPushPrivatesApi.showNotification(this, notificationMessage);
このコードブロックはフローティングウィンドウ内に表示されます
カスタム着信音通知
- 対応する着信音を事前にres/raw/に配置する必要があります。例:"coin.mp3"
- Android 8.0から、着信音はチャンネルで設定されます
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);
このコードブロックはフローティングウィンドウ内に表示されます
カスタムチャンネル通知
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);
// 着信音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";
// チャンネルID
String channelId = "money123";
// チャンネル名
String channelName = "money";
// チャンネル優先度
int importance = NotificationManager.IMPORTANCE_DEFAULT;
// チャンネル説明
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);
// 着信音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";
// チャンネルID
String channelId = "money123";
// チャンネル名
String channelName = "money";
// チャンネル優先度
int importance = NotificationManager.IMPORTANCE_DEFAULT;
// チャンネル説明
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;
}
このコードブロックはフローティングウィンドウ内に表示されます
カスタムレイアウト通知
// ここで定数を定義します。カスタムレイアウトのbuilderIdを表します
private static final int BUILDER_ID = 1001;
// まずカスタムレイアウトをEngagelabプライベートクラウド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);
// その後、カスタムレイアウト通知を送信します
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);
// ここで定数を定義します。カスタムレイアウトのbuilderIdを表します
private static final int BUILDER_ID = 1001;
// まずカスタムレイアウトをEngagelabプライベートクラウド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);
// その後、カスタムレイアウト通知を送信します
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);
このコードブロックはフローティングウィンドウ内に表示されます
カスタムジャンプ通知
// まず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();
// 次にカスタムジャンプ通知を送信します
NotificationMessage notificationMessage = new NotificationMessage()
.setMessageId("intent_" + System.currentTimeMillis())
.setTitle(this.getApplicationContext().getPackageName())
.setContentText("this is a intent notification")
.setContent(intentUri);
MTPushPrivatesApi.showNotification(this, notificationMessage);
// まず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();
// 次にカスタムジャンプ通知を送信します
NotificationMessage notificationMessage = new NotificationMessage()
.setMessageId("intent_" + System.currentTimeMillis())
.setTitle(this.getApplicationContext().getPackageName())
.setContentText("this is a intent notification")
.setContent(intentUri);
MTPushPrivatesApi.showNotification(this, notificationMessage);
このコードブロックはフローティングウィンドウ内に表示されます