Java Android应用程序推送更新数据
我刚开始用安卓系统开发,但我不懂java。所以我想开发一个应用程序来检查足球比赛的分数,一旦有新的数据可用,android应用程序必须以通知的方式将数据推送到用户 我的问题如下: 我可以使用一个不是我的网站服务器来获取数据,因为我没有服务器可以使用。因此,我不能使用C2DM 如果没有,解决方案是什么:TCP/IP连接,或者我可以根据自己的喜好自定义webview 提前感谢,,Java Android应用程序推送更新数据,java,android,eclipse,notifications,push,Java,Android,Eclipse,Notifications,Push,我刚开始用安卓系统开发,但我不懂java。所以我想开发一个应用程序来检查足球比赛的分数,一旦有新的数据可用,android应用程序必须以通知的方式将数据推送到用户 我的问题如下: 我可以使用一个不是我的网站服务器来获取数据,因为我没有服务器可以使用。因此,我不能使用C2DM 如果没有,解决方案是什么:TCP/IP连接,或者我可以根据自己的喜好自定义webview 提前感谢,, Roy我使用互联网数据的经验,不过这可能会帮助你开始 这是我用来下载网页并将其作为字符串返回的类,应该可以解析页面数据以
Roy我使用互联网数据的经验,不过这可能会帮助你开始 这是我用来下载网页并将其作为字符串返回的类,应该可以解析页面数据以提取所需的数据。你应该注意的是,网页更改格式很常见,这可能会破坏你的解析功能,也许你甚至没有意识到这一点 看看这个
感谢kurru的帮助,但这不意味着轮询数据会消耗资源和电池寿命吗?我可以让应用程序检查是否有新数据推送,当出现更改时,它会开始下载文件,如果是这样,我如何跟踪更改我不想为文本文件创建sql数据库,这将是低效的。您需要自己的服务器应用程序来维护下游,以提醒您有新数据。至于存储文件,您只需要最新的文件,SQLite存储大量文本没有问题,因此不应将其视为问题。
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()
{}
}