2011-09-07 24 views
0

我新开发的android,但我不在java。所以我想开发一个应用程序来检查足球比赛的比分,一旦有新的数据可用,android应用程序必须以通知的方式将这些数据推送给用户。Android应用程序推送更新数据

我的问题是:

我可以使用网站的服务器没有被雷到了,因为我没有一台服务器使用得到的数据。因此,我不能使用C2DM

如果不是什么解决方案:TCP/IP连接,或者我可以自定义一个webview我喜欢?

由于提前, 罗伊

回答

0

我使用互联网数据的经验,但是这可能会帮助你开始。

这是我用来下载网页并将它们作为字符串返回的类,应该可以解析页面数据以提取所需的数据。你应该小心的是,网页可能会改变它们的格式,这可能会破坏你的解析功能,也许你甚至没有意识到。

检查了这一点为Java HTML parsers

package AppZappy.NIRailAndBus; 

import java.net.MalformedURLException; 
import java.net.URL; 
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 


/** 
* Simplifies downloading of files from the internet 
*/ 
public class FileDownloading 
{ 
    /** 
    * Download a text file from the Internet 
    * @param targetUrl The URL of the file to download 
    * @return The string contents of the files OR NULL if error occurred 
    */ 
    public static String downloadFile(String targetUrl) 
    { 
     BufferedReader in = null; 
     try 
     { 
      // Create a URL for the desired page 
      URL url = new URL(targetUrl); 

      // Read all the text returned by the server 
      in = new BufferedReader(new InputStreamReader(url.openStream())); 

      StringBuilder sb = new StringBuilder(16384); // 16kb 
      String str = in.readLine(); 
      if (str != null) 
      { 
       sb.append(str); 
       str = in.readLine(); 
      } 
      while (str != null) 
      { 
       // str is one line of text; readLine() strips the newline 
       // character(s) 
       sb.append(C.new_line()); 
       sb.append(str); 
       str = in.readLine(); 
      } 

      String output = sb.toString(); 
      return output; 
     } 
     catch (MalformedURLException e) 
     {} 
     catch (IOException e) 
     {} 
     finally 
     { 
      try 
      { 
       if (in != null) in.close(); 
      } 
      catch (IOException e) 
      { 

      } 
     } 
     return null; 
    } 

    private FileDownloading() 
    {} 

} 
+0

感谢kurru对你有所帮助,但并不意味着这轮询消耗资源和电池寿命的数据?我可以让应用程序检查新数据(推送),当更改退出时,它会开始下载文件,如果可以,我如何跟踪更改,我不想为文本文件创建SQL数据库,这将是低效的。 – roy

+0

您需要您自己的服务器应用程序来维护会向您发送新数据的下游。至于存储文件,你只需要最近一次,SQLite没有问题存储大量的文本,所以不应该被视为一个问题。 – Kurru