WechatReceiver.java
1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.polysoft.nafmii.broadcast;
import android.content.Context;
import android.content.Intent;
import com.alibaba.fastjson.JSON;
import com.polysoft.nafmii.bean.Result;
public class WechatReceiver extends Receiver<Result> {
public static final String ACTION = "com.polysoft.nafmii.action_wechat";
protected WechatReceiver(Context context) {
super(context);
}
public static Receiver<Result> getInstance(Context context) {
Receiver<Result> receiver = getReceiver(WechatReceiver.class);
return null != receiver ? receiver : new WechatReceiver(context.getApplicationContext());
}
public static void sendBroadcast(Context context, Result data) {
Intent intent = new Intent().setAction(ACTION);
intent.putExtra("data", JSON.toJSONString(data));
onSendBroadcast(context, intent);
}
@Override
protected String[] getActions() {
return new String[]{ACTION};
}
@Override
protected Result onReceiverData(String action, Intent intent) {
if (ACTION.equals(action)) {
String dataJson = intent.getStringExtra("data");
return JSON.parseObject(dataJson, Result.class);
}
return null;
}
}