0

I have an app with contextual commands. After triggered a contextual command, it will make a HTTP request with a link and post the result on the card, something like, "Completed!". I want this card to be closed by itself after one second so that the user need not to tap to close it. Once the result card is closed, it will go back to contextual command lists with "Ok, glass" at footer and ready for next command.

May i know how to do that?

 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);
}

1 Answers1

1

You can use an Android Dialog for this:

  1. Use CardBuilder to create the "Completed" card using the MENU layout.
  2. Create a new instance of Dialog and set its content view to be the view returned by CardBuilder.getView.
  3. Show the dialog.
  4. Use Handler.postDelayed (or some similar mechanism) to automatically dismiss the dialog after the desired amount of time has passed.
Tony Allevato
  • 6,429
  • 1
  • 29
  • 34