Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在网站中自动检查字符串';s的源代码不存在?_Android_Html_Web - Fatal编程技术网

Android 如何在网站中自动检查字符串';s的源代码不存在?

Android 如何在网站中自动检查字符串';s的源代码不存在?,android,html,web,Android,Html,Web,我想每天检查一下 <h3>Tags</h3><ul class="ref-list"><li><a href="/platform/build/+/android-4.4.4_r1">android-4.4.4_r1</a> 标签 存在于中,如果不存在,则会收到通知 这样我就可以知道aosp的新版本何时发布。有什么想法吗?+1报警。您可能需要查看有关页面下载的HTTPClient文档: 示例代码段: HttpClien

我想每天检查一下

<h3>Tags</h3><ul class="ref-list"><li><a href="/platform/build/+/android-4.4.4_r1">android-4.4.4_r1</a>
标签 存在于中,如果不存在,则会收到通知


这样我就可以知道aosp的新版本何时发布。有什么想法吗?

+1报警。您可能需要查看有关页面下载的HTTPClient文档:

示例代码段:

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'...

剩下的就是解析结果,您就完成了。

获取页面源代码。把这个放在服务中

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
然后:

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");
}
String aospString=“Tags
  • ; 如果(!resString.contains(aospString)){ Log.d(LOGTAG,“ASOP不可用”); }

然后,您可以使用AlarmManager以固定频率计划执行

您是如何检查的?请发布代码。编写一个应用程序,每天在闹钟上下载,如果文件从昨天起发生了更改,请向您发送电子邮件/短信?作为一个桌面应用程序可能比移动应用程序更容易——大约有3行shell脚本。