我目前正在编写一个使用Push通知的Android应用程序.我的应用程序已成功注册Google服务器并获取ID,并且我有使用此ID的服务器端代码并将通知推送到收到的应用程序.
当收到推送时,我正在调用一个自定义类,它在一个线程内查询远程服务器以获取将在App中处理的信息.
调用的方法是这样的:
private Thread checkUpdate = new Thread() {
public void run() {
try {
URL updateURL = new URL("http://this.site.com/some/path");
URLConnection conn = updateURL.openConnection();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
/* Convert the Bytes read to a String. */
html = new String(baf.toByteArray());
mHandler.post(showUpdate);
} catch (Exception e) {
// Show message if there was an error …Run Code Online (Sandbox Code Playgroud)