11package com .jeepeng .react .xgpush .receiver ;
22
3- import android .app .NotificationManager ;
4- import android .content .Context ;
5- import android .content .Intent ;
6- import android .os .Bundle ;
7- import android .os .Environment ;
8- import android .util .Log ;
9-
10- import com .huawei .hms .support .api .push .PushReceiver ;
11- import com .jeepeng .react .xgpush .Constants ;
12-
13- import java .io .FileWriter ;
14- import java .io .IOException ;
3+ import com .tencent .android .hwpush .HWPushMessageReceiver ;
154
165/**
176 * 华为官方推送通道消息接收器
187 * Created by Jeepeng on 2018/3/11.
198 */
209
21- public class HWMessageReceiver extends PushReceiver {
22-
23- @ Override
24- public void onEvent (Context context , Event event , Bundle extras ) {
25- if (Event .NOTIFICATION_OPENED .equals (event ) || Event .NOTIFICATION_CLICK_BTN .equals (event )) {
26- int notifyId = extras .getInt (BOUND_KEY .pushNotifyId , 0 );
27- if (0 != notifyId ) {
28- NotificationManager manager = (NotificationManager ) context .getSystemService (Context .NOTIFICATION_SERVICE );
29- manager .cancel (notifyId );
30- }
31- }
32-
33- String message = extras .getString (BOUND_KEY .pushMsgKey );
34- String deviceToken = extras .getString (BOUND_KEY .deviceTokenKey );
35- int receiveType = extras .getInt (BOUND_KEY .receiveTypeKey );
36- String pushState = extras .getString (BOUND_KEY .pushStateKey );
37- int pushNotifyId = extras .getInt (BOUND_KEY .pushNotifyId , 0 );
38- // message:[{"id":"123456"}]
39- // Bundle[{receiveType=4, pushMsg=[{"id":"1"},{"name":"jeepeng"},{"sex":"man"}]}]
40-
41- if (Event .NOTIFICATION_OPENED .equals (event )) {
42- // 通知在通知栏被点击啦。。。。。
43- Intent intent = new Intent (Constants .ACTION_ON_NOTIFICATION_CLICKED );
44- Bundle bundle = new Bundle ();
45- bundle .putString ("content" , message );
46- intent .putExtra ("notification" , bundle );
47-
48- intent .putExtra ("content" , message );
49- intent .putExtra ("custom_content" , message );
50- context .sendBroadcast (intent );
51- }
52-
53- super .onEvent (context , event , extras );
54- }
55-
56- @ Override
57- public boolean onPushMsg (Context context , byte [] msg , Bundle bundle ) {
58- try {
59- String content = new String (msg , "UTF-8" );
60- Intent intent = new Intent (Constants .ACTION_ON_TEXT_MESSAGE );
61- intent .putExtra ("content" , content );
62- context .sendBroadcast (intent );
63- System .out .println (bundle );
64- Log .i ("HWMessageReceiver" , "收到PUSH透传消息,消息内容为:" + content );
65- } catch (Exception e ) {
66- e .printStackTrace ();
67- }
68- return super .onPushMsg (context , msg , bundle );
69- }
70-
71- @ Override
72- public void onPushState (Context context , boolean pushState ) {
73- super .onPushState (context , pushState );
74- }
75-
76- @ Override
77- public void onToken (Context context , String token , Bundle extras ) {
78- super .onToken (context , token , extras );
79- }
80-
81- @ Override
82- public void onToken (Context context , String token ) {
83- super .onToken (context , token );
84- }
85-
86- private void writeToFile (String conrent ) {
87- String SDPATH = Environment .getExternalStorageDirectory () + "/huawei.txt" ;
88- try {
89- FileWriter fileWriter = new FileWriter (SDPATH , true );
90-
91- fileWriter .write (conrent +"\r \n " );
92- fileWriter .flush ();
93- fileWriter .close ();
94- } catch (IOException e ) {
95- // TODO Auto-generated catch block
96- e .printStackTrace ();
97- }
98- }
99-
100-
10+ public class HWMessageReceiver extends HWPushMessageReceiver {
10111}
0 commit comments