1
1
package com .blankj .androidutilcode .activities ;
2
2
3
3
import android .app .Activity ;
4
+ import android .content .Context ;
4
5
import android .os .Bundle ;
5
6
import android .view .View ;
6
7
import android .widget .TextView ;
7
8
9
+ import com .blankj .androidutilcode .App ;
8
10
import com .blankj .androidutilcode .R ;
9
11
import com .blankj .utilcode .utils .NetworkUtils ;
10
12
19
21
public class NetworkActivity extends Activity
20
22
implements View .OnClickListener {
21
23
22
- TextView tvAboutNetwork ;
24
+ private TextView tvAboutNetwork ;
25
+ private Context mContext ;
23
26
24
27
@ Override
25
28
protected void onCreate (Bundle savedInstanceState ) {
26
29
super .onCreate (savedInstanceState );
27
30
setContentView (R .layout .activity_network );
28
31
29
32
tvAboutNetwork = (TextView ) findViewById (R .id .tv_about_network );
33
+ mContext = App .getInstance ();
30
34
31
35
findViewById (R .id .btn_open_wireless_settings ).setOnClickListener (this );
32
36
findViewById (R .id .btn_set_wifi_enabled ).setOnClickListener (this );
@@ -51,15 +55,15 @@ public void onClick(View view) {
51
55
}
52
56
53
57
private void setAboutNetwork () {
54
- tvAboutNetwork .setText ("isConnected: " + NetworkUtils .isConnected (this ) +
55
- "\n isAvailableByPing: " + NetworkUtils .isAvailableByPing (this ) +
56
- "\n getDataEnabled: " + NetworkUtils .getDataEnabled (this ) +
57
- "\n is4G: " + NetworkUtils .is4G (this ) +
58
- "\n getWifiEnabled: " + NetworkUtils .getWifiEnabled (this ) +
59
- "\n isWifiConnected: " + NetworkUtils .isWifiConnected (this ) +
60
- "\n isWifiAvailable: " + NetworkUtils .isWifiAvailable (this ) +
61
- "\n getNetworkOperatorName: " + NetworkUtils .getNetworkOperatorName (this ) +
62
- "\n getNetworkTypeName: " + NetworkUtils .getNetworkTypeName (this ) +
58
+ tvAboutNetwork .setText ("isConnected: " + NetworkUtils .isConnected (mContext ) +
59
+ "\n isAvailableByPing: " + NetworkUtils .isAvailableByPing (mContext ) +
60
+ "\n getDataEnabled: " + NetworkUtils .getDataEnabled (mContext ) +
61
+ "\n is4G: " + NetworkUtils .is4G (mContext ) +
62
+ "\n getWifiEnabled: " + NetworkUtils .getWifiEnabled (mContext ) +
63
+ "\n isWifiConnected: " + NetworkUtils .isWifiConnected (mContext ) +
64
+ "\n isWifiAvailable: " + NetworkUtils .isWifiAvailable (mContext ) +
65
+ "\n getNetworkOperatorName: " + NetworkUtils .getNetworkOperatorName (mContext ) +
66
+ "\n getNetworkTypeName: " + NetworkUtils .getNetworkTypeName (mContext ) +
63
67
"\n getIPAddress: " + NetworkUtils .getIPAddress (true ) +
64
68
"\n getDomainAddress: " + NetworkUtils .getDomainAddress ("baidu.com" )
65
69
);
0 commit comments