app/src/main/java/hu/kfg/wifimanager2/TimeoutKiller.java
public void connect(String username,Context context) {
	 if (Build.VERSION.SDK_INT >= 21 ){
		 final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		 for (Network net : cm.getAllNetworks()) {
			 if (cm.getNetworkInfo(net).getType() == ConnectivityManager.TYPE_WIFI) {
				 if (Build.VERSION.SDK_INT>=23) cm.bindProcessToNetwork(net);
				 ConnectivityManager.setProcessDefaultNetwork(net);
			 }
		 }
	 }
	    final String TAG = "TimeoutKiller";
	    HttpResponse response = null;
	    HttpClient client = new DefaultHttpClient();
	    HttpEntity entity;
	    HttpUriRequest request = new HttpGet("http://www.google.com/search?q="+username);
	  try {
	        response = client.execute(request);
	    } catch (Exception e3) {
	        e3.printStackTrace();
	    } 
		entity=null;
		try {
			
	    entity = response.getEntity();
		 Log.d(TAG,response.getStatusLine().toString());
		} catch (Exception e){
			Log.d(TAG,"Response error!");
			e.printStackTrace();
			
		}
	    String yourServer = "http://www.google.com/";
	 	HttpPost post = new HttpPost(yourServer);

	    List<NameValuePair> params = new ArrayList<NameValuePair>();
	    params.add(new BasicNameValuePair("q", username));
	    
	    try {
	        post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
	    } catch (UnsupportedEncodingException e2) {
	        e2.printStackTrace();
	    }
		
	    try {
	        response = client.execute(post);
	    } catch (Exception e1) {
			Log.v(TAG,"Cannot execute the POST request");
	        e1.printStackTrace();
	    } 
		try {
	    entity = response.getEntity();
		 Log.v(TAG,response.getStatusLine().toString());
		} catch (Exception err){
			Log.v(TAG,"Response error!");
			err.printStackTrace();
		 
		}
		if (KFGreceiver.is204PageAvailable(3000)) {
		 NotificationManager notificationManager = 
			 (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
			 notificationManager.cancelAll();
		}
	}
/**
 * Doing some network traffic, in order to avoid timeout (keep the connection alive)
 *
 */
Doing some network traffic, in order to avoid timeout (keep the connection alive)
Doing some network traffic in order to avoid timeout ( keep the connection alive )
public void connect(String username,Context context) {
	 if (Build.VERSION.SDK_INT >= 21 ){
		 final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		 for (Network net : cm.getAllNetworks()) {
			 if (cm.getNetworkInfo(net).getType() == ConnectivityManager.TYPE_WIFI) {
				 if (Build.VERSION.SDK_INT>=23) cm.bindProcessToNetwork(net);
				 ConnectivityManager.setProcessDefaultNetwork(net);
			 }
		 }
	 }
	    final String TAG = "TimeoutKiller";
	    HttpResponse response = null;
	    HttpClient client = new DefaultHttpClient();
	    HttpEntity entity;
	    HttpUriRequest request = new HttpGet("http://www.google.com/search?q="+username);
	  try {
	        response = client.execute(request);
	    } catch (Exception e3) {
	        e3.printStackTrace();
	    } 
		entity=null;
		try {
	    entity = response.getEntity();
		 Log.d(TAG,response.getStatusLine().toString());
		} catch (Exception e){
			Log.d(TAG,"Response error!");
			e.printStackTrace();
		}
	    String yourServer = "http://www.google.com/";
	 	HttpPost post = new HttpPost(yourServer);
	    List<NameValuePair> params = new ArrayList<NameValuePair>();
	    params.add(new BasicNameValuePair("q", username));
	    try {
	        post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
	    } catch (UnsupportedEncodingException e2) {
	        e2.printStackTrace();
	    }
	    try {
	        response = client.execute(post);
	    } catch (Exception e1) {
			Log.v(TAG,"Cannot execute the POST request");
	        e1.printStackTrace();
	    } 
		try {
	    entity = response.getEntity();
		 Log.v(TAG,response.getStatusLine().toString());
		} catch (Exception err){
			Log.v(TAG,"Response error!");
			err.printStackTrace();
		}
		if (KFGreceiver.is204PageAvailable(3000)) {
		 NotificationManager notificationManager = 
			 (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
			 notificationManager.cancelAll();
		}
	}
public void connect ( String username , Context context ) { if ( Build . VERSION . SDK_INT >= 21 ) { final ConnectivityManager cm = ( ConnectivityManager ) context . getSystemService ( Context . CONNECTIVITY_SERVICE ) ; for ( Network net : cm . getAllNetworks ( ) ) { if ( cm . getNetworkInfo ( net ) . getType ( ) == ConnectivityManager . TYPE_WIFI ) { if ( Build . VERSION . SDK_INT >= 23 ) cm . bindProcessToNetwork ( net ) ; ConnectivityManager . setProcessDefaultNetwork ( net ) ; } } } final String TAG = "TimeoutKiller" ; HttpResponse response = null ; HttpClient client = new DefaultHttpClient ( ) ; HttpEntity entity ; HttpUriRequest request = new HttpGet ( "http://www.google.com/search?q=" + username ) ; try { response = client . execute ( request ) ; } catch ( Exception e3 ) { e3 . printStackTrace ( ) ; } entity = null ; try { entity = response . getEntity ( ) ; Log . d ( TAG , response . getStatusLine ( ) . toString ( ) ) ; } catch ( Exception e ) { Log . d ( TAG , "Response error!" ) ; e . printStackTrace ( ) ; } String yourServer = "http://www.google.com/" ; HttpPost post = new HttpPost ( yourServer ) ; List < NameValuePair > params = new ArrayList < NameValuePair > ( ) ; params . add ( new BasicNameValuePair ( "q" , username ) ) ; try { post . setEntity ( new UrlEncodedFormEntity ( params , HTTP . UTF_8 ) ) ; } catch ( UnsupportedEncodingException e2 ) { e2 . printStackTrace ( ) ; } try { response = client . execute ( post ) ; } catch ( Exception e1 ) { Log . v ( TAG , "Cannot execute the POST request" ) ; e1 . printStackTrace ( ) ; } try { entity = response . getEntity ( ) ; Log . v ( TAG , response . getStatusLine ( ) . toString ( ) ) ; } catch ( Exception err ) { Log . v ( TAG , "Response error!" ) ; err . printStackTrace ( ) ; } if ( KFGreceiver . is204PageAvailable ( 3000 ) ) { NotificationManager notificationManager = ( NotificationManager ) context . getSystemService ( context . NOTIFICATION_SERVICE ) ; notificationManager . cancelAll ( ) ; } }
Doing some network traffic, in order to avoid timeout (keep the connection alive)
Doing some network traffic in order to avoid timeout ( keep the connection alive )