panlili2024
2025-03-05 134209ad70f82051da3ce63471df0cc8f778e57d
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.hdl.sdk.connect.cloud.broadcast;
 
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
 
/**
 * Created by Tong on 2021/11/9.
 * 网络请求广播
 * 需要应用层注册
 */
public abstract class CloudBroadcast extends BroadcastReceiver {
 
    public static final String KEY_API_CODE = "key_api_code";
    public static final String KEY_API_MESSAGE = "key_api_message";
 
    @Override
    public final void onReceive(Context context, Intent intent) {
        if (intent == null) return;
        String action = intent.getAction();
        if (action != null && !TextUtils.isEmpty(action)) {
            switch (action) {
                case CloudBroadcastAction.REFRESH_TOKEN_INVALID_ACTION:
                    onLogOut();
                    break;
                case CloudBroadcastAction.API_ERROR_ACTION:
                    try {
                        final String message = intent.getStringExtra(KEY_API_MESSAGE);
                        final int code = intent.getIntExtra(KEY_API_CODE, -1);
                        onOtherError(code, message);
                    } catch (Exception e) {
                        onOtherError(-1, e.getMessage());
                    }
                    break;
            }
        }
    }
 
    /**
     * 登录失效
     */
    public void onLogOut() {
        //会频繁收到
    }
 
 
    /**
     * 消息
     *
     * @param code    code
     * @param message 消息
     */
    public void onOtherError(int code, String message) {
 
    }
 
}