/*******************************************************************************
* Copyright 2013-2015 alladin-IT GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package at.alladin.rmbt.android.util;
import java.net.HttpURLConnection;
import java.net.URL;
import android.os.AsyncTask;
/**
*
* @author lb
*
*/
public class AsyncHtmlStatusCodeRetriever extends AsyncTask<String, Void, Integer> {
private ContentRetrieverListener listener;
/**
*
* @author lb
*
*/
public static interface ContentRetrieverListener {
public void onContentFinished(Integer statusCode);
}
/**
*
* @param listener
*/
public void setContentRetrieverListener(ContentRetrieverListener listener) {
this.listener = listener;
}
@Override
protected Integer doInBackground(String... params) {
try
{
URL url = new URL(params[0]);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
try {
connection.setConnectTimeout(3000);
connection.connect();
final int statusCode = connection.getResponseCode();
System.out.println("response code: " + statusCode);
return statusCode;
}
catch (Exception e) {
return null;
}
finally {
connection.disconnect();
}
}
catch (Exception e)
{
return null;
}
}
@Override
protected void onPostExecute(Integer result) {
super.onPostExecute(result);
if (this.listener != null) {
listener.onContentFinished(result);
}
}
}