0
我有一個應用程序與上下文命令。觸發一個上下文命令後,它會發出一個帶有鏈接的HTTP請求並在卡上發佈結果,如「Completed!」。我希望此卡一秒鐘後自行關閉,以便用戶不必點擊關閉它。一旦結果卡關閉,它將回到上下文命令列表,在頁腳處顯示「Ok,glass」並準備好下一個命令。如何在執行HTTP請求後自行關閉卡?
我可以知道該怎麼做嗎?
private class HTTPRequest extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... arg0) {
try {
if (mWhat.equalsIgnoreCase("GET")) {
// get json via YouTube API
URL url = new URL("http://example.com");
mUrlConnection = (HttpURLConnection)
url.openConnection();
InputStream in = new BufferedInputStream(
mUrlConnection.getInputStream());
int ch;
StringBuffer b = new StringBuffer();
while ((ch = in.read()) != -1) {
b.append((char) ch);
}
mResult = new String(b);
}
} catch (Exception e) {}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
mTvInfo.setText(mResult);
}
我不真的按照你的意見。你能給我看一些示例代碼嗎? – 2014-09-28 13:27:49