Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android check the net and go to the setting acvivity by intent

Android check the net and go to the setting acvivity by intent

編輯:關於Android編程

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


  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved