public class LessonsService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// your code
new GetData().execute();
/**
* Async Task to get data from URL
**/
class GetData extends AsyncTask<String, String, String> {
private InputStream is = null;
private String url = "http://www.kelidestan.com/fixed-url/kelidestan-1.php?name=kousha&city=tehran";
private String page_output = "";
@Override
protected String doInBackground(String... args) {
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
page_output = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
return page_output;
}
@Override
protected void onPostExecute(String page_output) {
try {
// display output of internet page (page_output string)
String str = page_output;
int num = str.length();
String str2 = getResources().getString(R.string.first_counter);
int num2 = str2.length();
if(num>num2){
//My Function Codes
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
return Service.START_FLAG_REDELIVERY;
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
}