android网络状态判断
import java.net.InetAddress;
import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.widget.ScrollView;
import android.widget.TextView;
public class NetAct extends Activity {
private TextView textView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
textView = new TextView(this);
textView.setBackgroundColor(0xffffffff);
textView.setTextColor(0xff0000ff);
textView.setTextSize(15.0f);
textView.setScrollBarStyle(TextView.SCROLLBARS_OUTSIDE_OVERLAY);
ScrollView scrollView = new ScrollView(this);
scrollView.addView(textView);
setContentView(scrollView);
getLocalHost();
getWifiInfo();
initNetworkInfo();
}
private void getLocalHost() {
try {
InetAddress iAdd = InetAddress.getLocalHost();
String line = "";
String hostName = iAdd.getHostName();
if (hostName != null) {
InetAddress[] adds = InetAddress.getAllByName(hostName);
for (int i = 0; i < adds.length; i++) {
iAdd = adds[i];
 
相关新闻>>
- 发表评论
-
- 最新评论 更多>>