1515 */
1616package com .huawei .push .examples ;
1717
18- import com .alibaba .fastjson .JSONObject ;
18+ import com .alibaba .fastjson .JSON ;
1919import com .huawei .push .android .AndroidNotification ;
20- import com .huawei .push .android .BadgeNotification ;
2120import com .huawei .push .android .ClickAction ;
22- import com .huawei .push .android .Color ;
23- import com .huawei .push .android .LightSettings ;
2421import com .huawei .push .exception .HuaweiMesssagingException ;
2522import com .huawei .push .message .AndroidConfig ;
2623import com .huawei .push .message .Message ;
2724import com .huawei .push .message .Notification ;
2825import com .huawei .push .messaging .HuaweiApp ;
2926import com .huawei .push .messaging .HuaweiMessaging ;
30- import com .huawei .push .model .Urgency ;
31- import com .huawei .push .model .Importance ;
32- import com .huawei .push .model .Visibility ;
3327import com .huawei .push .reponse .SendResponse ;
3428import com .huawei .push .util .InitAppUtils ;
3529
@@ -42,7 +36,7 @@ public void sendTestMessage() throws HuaweiMesssagingException {
4236 .setBody ("sample message body" )
4337 .build ();
4438
45- JSONObject multiLangKey = new JSONObject ();
39+ /* JSONObject multiLangKey = new JSONObject();
4640 JSONObject titleKey = new JSONObject();
4741 titleKey.put("en","好友请求");
4842 JSONObject bodyKey = new JSONObject();
@@ -53,46 +47,56 @@ public void sendTestMessage() throws HuaweiMesssagingException {
5347 LightSettings lightSettings = LightSettings.builder().setColor(Color.builder().setAlpha(0f).setRed(0f).setBlue(1f).setGreen(1f).build())
5448 .setLightOnDuration("3.5")
5549 .setLightOffDuration("5S")
56- .build ();
50+ .build();*/
5751
58- AndroidNotification androidNotification = AndroidNotification .builder ().setIcon ("/raw/ic_launcher2" )
59- .setColor ("#AACCDD" )
60- .setSound ("/raw/shake" )
61- .setDefaultSound (true )
62- .setTag ("tagBoom" )
52+ AndroidNotification androidNotification = AndroidNotification .builder ()
53+ .setTitle ("你有新的消息" )
54+ .setBody ("你在干啥?" )
55+ //.setIcon("/raw/ic_launcher2")
56+ //.setColor("#AACCDD")
57+ //.setSound("/raw/shake")
58+ //.setDefaultSound(true)
59+ //.setTag("tagBoom")
6360 .setClickAction (ClickAction .builder ().setType (2 ).setUrl ("https://www.huawei.com" ).build ())
64- .setBodyLocKey ("key2" )
65- .addBodyLocArgs ("boy" ).addBodyLocArgs ("dog" )
66- .setTitleLocKey ("key1" )
67- .addTitleLocArgs ("Girl" ).addTitleLocArgs ("Cat" )
68- .setChannelId ("Your Channel ID" )
69- .setNotifySummary ("some summary" )
70- .setMultiLangkey (multiLangKey )
71- .setStyle (1 )
72- .setBigTitle ("Big Boom Title" )
73- .setBigBody ("Big Boom Body" )
74- .setAutoClear (86400000 )
75- .setNotifyId (486 )
76- .setGroup ("Group1" )
77- .setImportance (Importance .LOW .getValue ())
78- .setLightSettings (lightSettings )
79- .setBadge (BadgeNotification .builder ().setAddNum (1 ).setBadgeClass ("Classic" ).build ())
80- .setVisibility (Visibility .PUBLIC .getValue ())
81- .setForegroundShow (true )
61+ // .setBodyLocKey("key2")
62+ // .addBodyLocArgs("boy").addBodyLocArgs("dog")
63+ // .setTitleLocKey("key1")
64+ // .addTitleLocArgs("Girl").addTitleLocArgs("Cat")
65+ // .setChannelId("Your Channel ID")
66+ // .setNotifySummary("some summary")
67+ //// .setMultiLangkey(multiLangKey)
68+ // .setStyle(1)
69+ // .setBigTitle("Big Boom Title")
70+ // .setBigBody("Big Boom Body")
71+ // .setAutoClear(86400000)
72+ // .setNotifyId(486)
73+ // .setGroup("Group1")
74+ // .setImportance(Importance.LOW.getValue())
75+ //// .setLightSettings(lightSettings)
76+ // .setBadge(BadgeNotification.builder().setAddNum(1).setBadgeClass("Classic").build())
77+ // .setVisibility(Visibility.PUBLIC.getValue())
78+ // .setForegroundShow(true)
8279 .build ();
8380
84- AndroidConfig androidConfig = AndroidConfig .builder ().setCollapseKey (-1 )
85- .setUrgency (Urgency .HIGH .getValue ())
86- .setTtl ("10000s" )
87- .setBiTag ("the_sample_bi_tag_for_receipt_service" )
81+ AndroidConfig androidConfig = AndroidConfig .builder ()
82+ //.setCollapseKey(-1)
83+ //.setUrgency(Urgency.NORMAL.getValue())
84+ //.setTtl("10000s")
85+ //.setBiTag("the_sample_bi_tag_for_receipt_service")
8886 .setNotification (androidNotification )
8987 .build ();
9088
91- Message message = Message .builder ().setNotification (notification )
89+ Message message = Message .builder ()
90+ //.setNotification(notification)
9291 .setAndroidConfig (androidConfig )
93- .addToken ("AND8rUp4etqJvbakK7qQoCVgFHnROXzH8o7B8fTl9rMP5VRFN83zU3Nvmabm3xw7e3gZjyBbp_wfO1jP-UyDQcZN_CtjBpoa7nx1WaVFe_3mqXMJ6nXJNUZcDyO_-k3sSw " )
92+ .addToken ("IQAAAACy0LgAAADBbzjXeF4Y-BTmHuEkn6fwOdK0a-FP1wUHByFpI-gHHg7fcxNc1eEDG0jNWNtS_vQZ91IqBMJssJoYpCuwVXtyeG8J2xYqLHwu5Q " )
9493 .build ();
9594
96- SendResponse response = huaweiMessaging .sendMessage (message , true );
95+ SendResponse response = huaweiMessaging .sendMessage (message , false );
96+ System .out .println (JSON .toJSONString (response ));
97+ }
98+
99+ public static void main (String [] args ) throws HuaweiMesssagingException {
100+ new SendTestMessage ().sendTestMessage ();
97101 }
98102}
0 commit comments