详细解答可以参考3. 自定义样式通知(V2.3.3及以上版本开始支持)">官方帮助文档
Android Push SDK支持用户自定义通知样式,用户可以设定自己的通知样式,涉及的内容包括通知的提醒方式(声音、震动、静默),通知在状态栏的显示图标,推送消息应用内到达时是否创建通知以及自定义通知布局文件等。自定义样式通知的设置包括两部分:
BasicCustomPushNotification
;2)AdvancedCustomPushNotification
。其中BasicCustomPushNotification
用户设置基础样式,包括提醒方式、状态栏图标以及当推送消息到达时应用正处于前台情况下是否创建该通知等。AdvancedCustomPushNotification
是BasicCustomPushNotification
的子类,继承了BasicCustomPushNotification
的所有方法,同时还可以设置通知样式布局文件BasicCustomPushNotification
BasicCustomPushNotification notification = new BasicCustomPushNotification();
notification.setRemindType(BasicCustomPushNotification.REMIND_TYPE_SOUND);
notification.setStatusBarDrawable(R.drawable.logo_yuanjiao_120);
boolean res = CustomNotificationBuilder.getInstance().setCustomNotification(1, notification);
AdvancedCustomPushNotification
AdvancedCustomPushNotification notification = new AdvancedCustomPushNotification(R.layout.notitfication_layout, R.id.m_icon, R.id.m_title, R.id.m_text);
notification.setServerOptionFirst(true);
notification.setBuildWhenAppInForeground(false);
boolean res = CustomNotificationBuilder.getInstance().setCustomNotification(2, notification);
OpenApi
客户端设置完成后,服务端在推送通知时需要利用OpenApi指明对应的自定义样式ID
final SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd HH:mm:ss");
final String date = dateFormat.format(new Date());
PushRequest pushRequest = new PushRequest();
// 推送目标
pushRequest.setAppKey(appKey);
pushRequest.setTarget("device"); //推送目标: device:推送给设备; account:推送给指定帐号,tag:推送给自定义标签; all: 推送给全部
pushRequest.setTargetValue("deviceId");
// 推送配置
pushRequest.setType(1); // 0:表示消息(默认为0), 1:表示通知
pushRequest.setTitle(date); // 消息的标题
pushRequest.setBody("PushRequest body"); // 消息的内容
pushRequest.setSummary("PushRequest summary"); // 通知的摘要
pushRequest.setAndroidNotificationBarType(2);//设置的通知样式ID,通知栏自定义样式范围0-100
// 推送配置: Android
pushRequest.setAndroidOpenType("1"); // 点击通知后动作,1:打开应用 2: 打开应用Activity 3:打开 url
pushRequest.setAndroidExtParameters("{\"_NOTIFICATION_BAR_STYLE_\":\"2\"}");
public BasicCustomPushNotification();
public BasicCustomPushNotification(int drawable, int flags, int remindType);
public int getStatusBarDrawable()
public void setStatusBarDrawable(int statusBarDrawable);
public int getRemindType();
public void setRemindType(int remindType);
public int getNotificationFlags();
public void setNotificationFlags(int notificationFlags);
public boolean isServerOptionFirst();
public void setServerOptionFirst(boolean serverOptionFirst);
public boolean isBuildWhenAppInForeground();
public void setBuildWhenAppInForeground(boolean buildWhenAppInForeground);
AdvancedCustomPushNotification
是BasicCustomPushNotification
的子类,继承了上文中BasicCustomPushNotification
的所有方法。
public AdvancedCustomPushNotification( int view, int iconViewId, int titleViewId, int contentViewId);
public void setIcon(int icon);
public int getIcon();
public static CustomNotificationBuilder getInstance();
public boolean setCustomNotification(int customNotificationId, BasicCustomPushNotification notification);
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。