we used need to check the user's net is work before we need to connect the work.how can we do this?
just see the code:
private void checkNet(){
ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
if(info !=null && info.isConnected()){
Toast.makeText(this, "net is working", 0).show();
}else{
Toast.makeText(this, "net isn't work", 0).show();
// jump to the setting
Intent intent = new Intent();
intent.setClassName("com.android.setting", "com.android.settings.WirelessSettings");
startActivity(intent);
}
}
and u need to add the permission to ur AndroidManifest.xml:
android.permission.ACCESS_NETWORK_STATE