0
請參閱下面的代碼。當我在我的設備安裝下面的代碼,然後我打開該程序安裝後立即,我看到以下結果:互聯網連接並檢查它
Please Try
但是當我關閉程序,我想重新打開程序停止。爲什麼?哪裏有問題?
public class MainActivity extends Activity {
ConnectivityManager connectivityManager;
TextView textView;
NetworkInfo networkInfo;
boolean v;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textView);
connectivityManager=(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
v = networkInfo.isConnected();
if(v == false)
textView.setText("Please Try");
else if(v == true)
textView.setText("Connect");
}
它是如何崩潰之前?您是否已將ACCESS_NETWORK_STATE添加到清單中? – Blackbelt
發佈堆棧跟蹤 – GVillani82
您還可以顯示其他重寫的方法嗎? – helleye