0

我想检查移动数据连接,如果它打开或关闭,我将为它定义一个事件。数据单元打开时,显示移动数据图标,当移动数据关闭时,移动数据图标也将隐藏!

4

1 回答 1

0

确定您是否有互联网连接

ConnectivityManager cm =
        (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null &&
                      activeNetwork.isConnectedOrConnecting();

确定互联网连接的类型

ConnectivityManager cm =
        (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
boolean isMetered = cm.isActiveNetworkMetered();

欲了解更多信息,请单击此处

于 2020-06-02T03:58:17.647 回答