一.网络连接判断
public void doClick(View v){
switch(v.getId()){
case R.id.network:
if(isNetWorkConnected(MainActivity.this)==true){Toast.makeText().....}
case :
}
}
public boolean isNetWorkConnected(Context context){//以上下文做完参数
if(context!=null){
ConnectivityManager mConnectivityManager=(ConnectivityManager)context.getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo mNetWorkInfo=mConnectivityManager.getActiveNetworkInfo();
if(mNetWorkInfo!=null){
return mNetWorkInfo.isAvailable();
}
}
return false;//未连接返回false
}
二.系统服务