Created
August 3, 2019 07:57
-
-
Save elktros/b3cf5b7f878e2ec544dbb586d5155185 to your computer and use it in GitHub Desktop.
Quadruped_Robot_requestTask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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