package com.example.week;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
/**
* Created by 生哥 on 2017/12/2.
*/
public class Fragment3 extends Fragment {
private WifiManager wm;
private TextView tv3;
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment3, container, false);
tv3 = view.findViewById(R.id.tv3);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
wm = (WifiManager) getActivity().getApplicationContext()
.getSystemService(Context.WIFI_SERVICE);
if (wm != null){
boolean b = wm.isWifiEnabled();
if(b){
tv3.setText("没开");
}else {
tv3.setText("开了");
}
}else {
tv3.setText("没有");
}
}
}
转载于:https://www.cnblogs.com/wangwensheng/p/7975418.html