0

I want to check daily if

<h3>Tags</h3><ul class="ref-list"><li><a href="/platform/build/+/android-4.4.4_r1">android-4.4.4_r1</a>

is present in https://android.googlesource.com/platform/build/ and be notified if isn't.

This is so I will know when new versions of aosp are released. Any ideas?

  • How did you check?please post code. – Giru Bhai Jun 25 '14 at 05:04
  • Write an app that downlods it daily on an alarm and emails/smses you if the file has changed since yesterday? Probably easier as a desktop app than a mobile- its about 3 lines of shell scripting. – Gabe Sechan Jun 25 '14 at 05:04

2 Answers2

1

Fetch page source code. Put this inside a Service. :

HttpClient httpclient = new DefaultHttpClient(); // Create HTTP Client
HttpGet httpget = new HttpGet("http://yoururl.com"); // Set the action you want to do
HttpResponse response = httpclient.execute(httpget); // Executeit
HttpEntity entity = response.getEntity(); 
InputStream is = entity.getContent(); // Create an InputStream with the response
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) // Read line by line
    sb.append(line + "\n");

String resString = sb.toString(); // Result is here

is.close(); // Close

Then :

String aospString = "<h3>Tags</h3><ul class=\"ref-list\"><li><a href=\"/platform/build/+/android-4.4.4_r1\">android-4.4.4_r1</a>";
if(!resString.contains(aospString)) {
    Log.d(LOGTAG, "ASOP Unavailable");
}

You can then use the AlarmManager to schedule the execution in a fixed frequency. Here.

Community
  • 1
  • 1
Shivam Verma
  • 7,973
  • 3
  • 26
  • 34
0

+1 for the alarm. And you may want to look into the HTTPClient documentation regarding the page download:

http://developer.android.com/reference/org/apache/http/client/HttpClient.html

Sample snippet:

HttpClient client = new DefaultHttpClient();
String uri = "https://android.googlesource.com/platform/build/"
HttpGet request = new HttpGet( uri );

try {
  HttpResponse response = client.execute(request);
  StatusLine status = response.getStatusLine();
  if (status.getStatusCode() != 200) {
      throw new IOException("Invalid response from server: " + status.toString());
  }

  HttpEntity entity = response.getEntity();
  InputStream inputStream = entity.getContent();
  ByteArrayOutputStream content = new ByteArrayOutputStream();
} catch( Exception ex ) {
  throw new Exception( "Something went wrong while accessing '" + uri + "':"  + ex.getLocalizedMessage() );
}

  int readBytes = 0;
  byte[] sBuffer = new byte[1024];
  while ((readBytes = inputStream.read(sBuffer)) != -1) {
      content.write(sBuffer, 0, readBytes);
  }

  String dataAsString = new String(content.toByteArray()); 

  // TODO: Parse 'dataAsString'...

Whats left is parsing the result and you're done.

07713
  • 36
  • 3