位置 | 定制点 | 定制方式 |
---|---|---|
通知栏 | 是否弹通知栏提醒 | 实现接口 |
通知栏ticker | 自定义通知栏ticker | 实现接口 |
通知栏图标 | 自定义通知栏图标 | 实现接口 |
通知栏title | 自定义通知栏title | 实现接口 |
通知栏提示音 | 自定义通知栏提示音 | 实现接口 |
通知栏提示文案 | 自定义收到消息时通知栏的提示文案 | 实现接口 |
通知栏跳转 | 自定义点击通知栏的跳转Intent | 实现接口 |
消息提醒 | 弹出通知栏消息的情况下是否响铃,是否震动 (支持对单个会话进行消息提醒的设置) | 实现接口 |
IMNotification实现了对通知栏提醒的定制,以下将对通知栏提醒定制的各个功能进行介绍,具体使用方式请参考demo NotificationInitSampleHelper.java
//其中yourclass是继承自IMNotification的自定义类 AdviceBinder.bindAdvice(PointCutEnum.NOTIFICATION_POINTCUT, yourclass_.class);
如果对注册或者使得自定义不清楚的,请看这里
以下方法如果有需要,可以选择性地Override。
//设置是否开启通知提醒,参数设置 true: 开启通知栏提醒,false :关闭通知栏提醒 imKit.setEnableNotification(true);
/** * 自定义通知栏ticker * @param conversation * 收到消息的会话 * @param message * 收到的消息 * @param totalUnReadCount * 会话中消息未读数 * @return * 如果返回null,则使用SDK默认的ticker */ @Override public String getTicker(YWConversation conversation, YWMessage message, int totalUnReadCount) { return "123456"; }
/** * 获取通知栏图标Icon * @return 资源id */ @Override public int getNotificationIconResID() { return R.drawable.aliwx_notification_bg; }
/** * 获取通知栏显示Title * @return title */ @Override public String getAppName() { return "我的OpenIM"; }
/** * 返回自定义提示音资源Id * @return 提示音资源Id,返回0则使用SDK默认的提示音 */ @Override public int getNotificationSoundResId() { return 0; }
/** * 收到消息时,自定义消息通知栏的提示文案 * @param conversation * @param message * @param totalUnReadCount * @return,如果返回空,则使SDK默认的文案格式 */ @Override public String getNotificationTips(YWConversation conversation, YWMessage message, int totalUnReadCount) { return "自定义文案,未读消息数为:" + totalUnReadCount; }
/** * 收到消息时的自定义通知栏点击Intent * @param conversation * 收到消息的会话 * @param message * 收到的消息 * @param totalUnReadCount * 会话中消息未读数 * @return * 如果返回null,则使用全局自定义Intent */ public Intent getCustomNotificationIntent(YWConversation conversation, YWMessage message, int totalUnReadCount) { //以下仅为示例代码,Intent需要开发者根据不同目的自己实现 Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setClass(DemoApplication.getContext(), FragmentTabs.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); return intent; }
/** * 是否开启免打扰模式,若开启免打扰模式则收到新消息时不发送通知栏提醒,只在会话列表页面显示未读数 * 若开启免打扰模式,则声音提醒和震动提醒会失效,即收到消息时不会有震动和提示音 * @param conversation 会话id * @param message 收到的消息 * @return true:开启, false:不开启 */ @Override public boolean needQuiet(YWConversation conversation, YWMessage message) { if (conversation.getConversationType() == YWConversationType.Tribe){ return true; } } /** * 收到通知栏消息时是否震动提醒,该设置在没有开启免打扰模式的情况下才有效 * @param conversation 会话id * @param message 收到的消息 * @return true:震动,false:不震动 */ @Override public boolean needVibrator(YWConversation conversation, YWMessage message) { if (conversation.getConversationType() == YWConversationType.Tribe){ return false; } } /** * 收到通知栏消息时是否有声音提醒,该设置在没有开启免打扰模式的情况下才有效 * @param conversation 会话id * @param message 收到的消息 * @return true:有提示音,false:没有提示音 */ @Override public boolean needSound(YWConversation conversation, YWMessage message) { if (conversation.getConversationType() == YWConversationType.Tribe){ return false; } }