hxb
2024-06-25 70a4c1baac1415ea65d9727284703a3d5585036d
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
package com.hdl.photovoltaic.broadcast;
 
 
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
 
import com.hdl.photovoltaic.config.ConstantManage;
import com.hdl.photovoltaic.enums.NetworkType;
import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus;
 
import org.greenrobot.eventbus.EventBus;
 
 
/**
 * 监听网络状态变化的广播
 */
public class NetworkChangeReceiver extends BroadcastReceiver {
 
    @Override
    public void onReceive(Context context, Intent intent) {
        //todo 已经转在NetworkUtils里面实现
//        ConnectivityManager connectionManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//        NetworkInfo networkInfo = connectionManager.getActiveNetworkInfo();
//        if (networkInfo != null && networkInfo.isAvailable()) {
//            switch (networkInfo.getType()) {
//                case ConnectivityManager.TYPE_MOBILE:
//                    BaseEventBus mobile_network = new BaseEventBus();
//                    mobile_network.setTopic(ConstantManage.network_change_post);
//                    mobile_network.setType(NetworkType.g_4.toString());
//                    mobile_network.setData("正在使用2G/3G/4G网络");
//                    EventBus.getDefault().post(mobile_network);
//                    break;
//                case ConnectivityManager.TYPE_WIFI:
//                    BaseEventBus wif_network = new BaseEventBus();
//                    wif_network.setTopic(ConstantManage.network_change_post);
//                    wif_network.setType(NetworkType.wifi.toString());
//                    wif_network.setData("正在使用wifi上网");
//                    EventBus.getDefault().post(wif_network);
//                    break;
//                default:
//                    break;
//            }
//
//        } else {
//            BaseEventBus baseEventBus = new BaseEventBus();
//            baseEventBus.setTopic(ConstantManage.network_change_post);
//            baseEventBus.setType(NetworkType.no_network.toString());
//            baseEventBus.setData("当前无网络连接");
//            EventBus.getDefault().post(baseEventBus);
//        }
 
    }
 
}