Code example for ConnectivityManager: Querying Network Reachability

Methods: getActiveNetworkInfogetBackgroundDataSetting

	public static boolean hasNetworkConnection(Context context){
		ConnectivityManager mConnectivity 
				= (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);  
		  Log.v(TAG, "hasNetworkConnection");
		 // 检查网络连接,如果无网络可用,就不需要进行连网操作等     
		 NetworkInfo info = mConnectivity.getActiveNetworkInfo();    
		 if (info == null ||   
		         !mConnectivity.getBackgroundDataSetting()) {   
		         return false;     
		 return true; 
	public static double[] getLocationInfo(String address)  
		Log.v(TAG, address);
		//address 中,在所有答谢字母前,都加上%20 
        // 定义一个HttpClient,用于向指定地址发送请求   
        HttpClient client = new DefaultHttpClient();  
Connect your IDE to all the code out there  Get Codota for Java