package com.example.wifitest;import android.os.Bundle;import android.app.Activity;import android.content.Context;import android.view.Menu;import android.widget.TextView;import android.widget.Toast;import java.util.List; import android.content.Context; import android.net.ConnectivityManager;import android.net.NetworkInfo.State;import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.net.wifi.WifiManager.WifiLock; public class MainActivity extends Activity { TextView txt3G; TextView txtWifi; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); txt3G=(TextView)findViewById(R.id.txt3G); txtWifi=(TextView)findViewById(R.id.txtWifi); ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); //mobile 3G Data Network State mobile = conMan.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); txt3G.setText(mobile.toString()); //显示3G网络连接状态 //wifi State wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); txtWifi.setText(wifi.toString()); //显示wifi连接状态 if(wifi.toString().equals("DISCONNECTED")){ Toast.makeText(MainActivity.this, "未连接wifi", Toast.LENGTH_LONG).show(); } } private void checkNetworkInfo() { } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }