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) { } }