Skip to content

Instantly share code, notes, and snippets.

@elktros
Created August 3, 2019 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elktros/b3cf5b7f878e2ec544dbb586d5155185 to your computer and use it in GitHub Desktop.
Save elktros/b3cf5b7f878e2ec544dbb586d5155185 to your computer and use it in GitHub Desktop.
Quadruped_Robot_requestTask
import android.app.Activity;
import android.os.AsyncTask;
import ai.api.AIServiceContext;
import ai.api.AIServiceException;
import ai.api.android.AIDataService;
import ai.api.model.AIRequest;
import ai.api.model.AIResponse;
public class RequestTask extends AsyncTask<AIRequest, Void, AIResponse> {
Activity activity;
private AIDataService aiDataService;
private AIServiceContext customAIServiceContext;
RequestTask(Activity activity, AIDataService aiDataService, AIServiceContext customAIServiceContext){
this.activity = activity;
this.aiDataService = aiDataService;
this.customAIServiceContext = customAIServiceContext;
}
@Override
protected AIResponse doInBackground(AIRequest... aiRequests) {
final AIRequest request = aiRequests[0];
try {
return aiDataService.request(request, customAIServiceContext); // dialogflow request is made
} catch (AIServiceException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(AIResponse aiResponse) {
((Main2chatActivity)activity).callback(aiResponse);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment