{"id":19778904,"url":"https://github.com/dialogflow/dialogflow-android-client","last_synced_at":"2025-04-04T13:09:12.181Z","repository":{"id":18658330,"uuid":"21865662","full_name":"dialogflow/dialogflow-android-client","owner":"dialogflow","description":"Android SDK for Dialogflow","archived":false,"fork":false,"pushed_at":"2019-02-20T18:47:46.000Z","size":2658,"stargazers_count":575,"open_issues_count":69,"forks_count":269,"subscribers_count":68,"default_branch":"master","last_synced_at":"2025-03-28T12:04:14.078Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://dialogflow.com","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dialogflow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-15T15:41:28.000Z","updated_at":"2025-03-17T12:05:15.000Z","dependencies_parsed_at":"2022-09-05T17:00:10.490Z","dependency_job_id":null,"html_url":"https://github.com/dialogflow/dialogflow-android-client","commit_stats":null,"previous_names":["speaktoit/api-ai-android-sdk"],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dialogflow%2Fdialogflow-android-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dialogflow%2Fdialogflow-android-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dialogflow%2Fdialogflow-android-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dialogflow%2Fdialogflow-android-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dialogflow","download_url":"https://codeload.github.com/dialogflow/dialogflow-android-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247178900,"owners_count":20896935,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T05:32:36.318Z","updated_at":"2025-04-04T13:09:12.161Z","avatar_url":"https://github.com/dialogflow.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DEPRECATED Android SDK for api.ai\n\n| Deprecated |\n|-------|\n| This Dialogflow client library and Dialogflow API V1 [have been deprecated and will be shut down on October 23th, 2019](https://blog.dialogflow.com/post/migrate-to-dialogflow-api-v2/). Please migrate to Dialogflow API V2 and the [v2 client library](https://cloud.google.com/dialogflow-enterprise/docs/reference/libraries/java) |\n\n[![Release status](https://travis-ci.org/api-ai/apiai-android-client.svg?branch=master)](https://travis-ci.org/api-ai/apiai-android-client) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/ai.api/sdk/badge.svg)](https://maven-badges.herokuapp.com/maven-central/ai.api/sdk)\n\nThe API.AI Android SDK makes it easy to integrate speech recognition with [API.AI](http://www.api.ai) natural language processing API on Android devices. API.AI allows using voice commands and integration with dialog scenarios defined for a particular agent in API.AI.\n\nTwo permissions are required to use the API.AI Android SDK:\n\n* **android.permission.INTERNET** for internet access\n* **android.permission.RECORD_AUDIO** for microphone access\n\nAdd this dependencies to your project to use SDK\n\n```\ncompile 'ai.api:sdk:2.0.7@aar'\n// api.ai SDK dependencies\ncompile 'com.android.support:appcompat-v7:23.2.1'\n```\n\nCurrently, speech recognition is performed using Google's Android SDK, either on the client device or in the cloud. Recognized text is passed to the API.AI through HTTP requests. Also you can try Speaktoit recognition engine (Use [AIConfiguration.RecognitionEngine.Speaktoit](https://github.com/api-ai/api-ai-android-sdk/blob/master/ailib/src/main/java/ai/api/AIConfiguration.java#L37)).\n\nAuthentication is accomplished through setting the client access token when initializing an [AIConfiguration](https://github.com/api-ai/api-ai-android-sdk/blob/master/ailib/src/main/java/ai/api/android/AIConfiguration.java) object. The client access token specifies which agent will be used for natural language processing.\n\n**Note:** The API.AI Android SDK only makes query requests, and cannot be used to manage entities and intents. Instead, use the API.AI user interface or REST API to  create, retrieve, update, and delete entities and intents.\n\n* [Running the Sample Code](#running_sample)\n* [Getting Started with Your Own App](#getting_started)\n* [Tutorial](#tutorial)\n* [Brief Integration Instruction (for experienced developers)](docs/integration.md)\n* [Feature examples](#feature-examples)\n    * [User specified contexts](#user-specified-contexts)\n    * [User specified entities](#user-specified-entities)\n    * [Bluetooth support](#bluetooth-support)\n* [Troubleshooting](#troubleshooting)\n\n# \u003ca name=\"running_sample\" /\u003eRunning the Sample Code\n\nThe API.AI Android SDK comes with a simple sample that illustrates how voice commands can be integrated with API.AI. Use the following steps to run the sample code:\n\n1. Have an API.AI agent created that has entities and intents. See the [API.AI documentation](http://api.ai/docs/getting-started/5-min-guide/) on how to do this.\n2. Open [Android Studio](https://developer.android.com/sdk/installing/studio.html).\n3. Import the **api-ai-android-master** directory.\n4. Open the SDK Manager and be sure that you have installed Android Build Tools 19.1.\n5. In the Project browser, open **apiAISampleApp/src/main/java/ai.api.sample/Config**.\n6. Towards the top of the file, you will see a declaration of a static final string called *ACCESS_TOKEN*. Set its value to be the client access token of your agent.\n7. Attach an Android device, or have the emulator set up with an emulated device.\n8. From the **Run** menu, choose **Debug** (or click the Debug symbol). Choose your device.\n9. You should see an app running with three buttons: **Listen**, **StopListen**, and **Cancel**.\n10. Click **Listen** and say a phrase that will be understood by your agent. Wait a few seconds. The Java will appear that is returned by the API.AI service.\n\n# \u003ca name=\"getting_started\" /\u003eGetting Started with Your Own App\n\nThis section describes what you need to do to get started with your own app that uses the API.AI Android SDK. The first part provides an overview of how to use the SDK, and the second part is a tutorial with detailed step-by-step instructions for creating your own app.\n\nIf you are an experienced developer you might use [brief integration instruction](docs/integration.md).\n\n## Overview\n\nTo implement speech recognition and natural language processing features in your app, you must first add the API.AI SDK library to your project. There are two ways to accomplish this. The first way is recommended:\n\n1. Add a dependency to your *build.gradle* file. Add the following line to your **build.gradle** file. (In the sample app, the **apiAISampleApp/build.gradle** is an example of how to do this.)\n\n    ```\n    compile 'ai.api:sdk:2.0.7@aar'\n    ```\n    \n2. (Not recommended) Download the library source code from github, and attach it to your project.\n\nNow you can use API.AI service features in your app using either integrated speech recognition or using your own speech recognition.\n\n## Using integrated speech recognition\n\nOnce you've added the SDK library, follow these steps:\n\n1. Add two permissions into the AndroidManifest:\n    * **android.permission.INTERNET**\n    * **android.permission.RECORD_AUDIO**\n    \n2. Create a class that implements the AIListener interface. This class will process responses from API.AI. (AIRequest, AIResponse are not a part of \"ai.api:sdk:2.0.7@aar\", they are a part of \"ai.api:libai:1.6.12\", if you haven't added it until now add \n```\n\n    compile 'ai.api:libai:1.6.12'\n```\n\nto yor app level gradle file.\n\n\n)\n\n    ```java\n    public interface AIListener {\n        void onResult(AIResponse result); // here process response\n        void onError(AIError error); // here process error\n        void onAudioLevel(float level); // callback for sound level visualization\n        void onListeningStarted(); // indicate start listening here\n        void onListeningCanceled(); // indicate stop listening here\n        void onListeningFinished(); // indicate stop listening here\n    }\n    ```\n\n3. Create an instance of AIConfiguration, specifying the access token, locale, and recognition engine.\n\n    ```java\n    final AIConfiguration config = new AIConfiguration(\"CLIENT_ACCESS_TOKEN\",\n                AIConfiguration.SupportedLanguages.English,\n                AIConfiguration.RecognitionEngine.System);\n    ```\n\n4. Use the AIConfiguration object to get a reference to the AIService, which will make the query requests.\n\n    ```java\n    AIService aiService = AIService.getService(context, config);\n    ```\n\n5. Set the AIListener instance for the AIService instance.\n\n    ```java\n    aiService.setListener(yourAiListenerInstance);\n    ```\n\n6. Launch listening from the microphone via the **startListening** method. The SDK will start listening for the microphone input of the mobile device.\n\n    ```java\n    aiService.startListening();\n    ```\n\n7. To stop listening and start the request to the API.AI service using the current recognition results, call the **stopListening** method of the AIService class.\n\n    ```java\n    aiService.stopListening();\n    ```\n\n8. To cancel the listening process without sending a request to the API.AI service, call the **cancel** method of the AIService class.\n\n    ```java\n    aiService.cancel();\n    ```\n\n9. If there are no errors, you can get the result using the **AIResponse.getResult** method. From there, you can obtain the action and parameters.\n\n    ```java\n    public void onResult(final AIResponse response) {\n        Log.i(TAG, \"Action: \" + result.getAction());\n        // process response object\n    }\n    ```\n\n## Using your own speech recognition\n\nThis section assumes that you have performed your own speech recognition and that you have text that you want to process as natural language. Once you've added the SDK library, follow these steps:\n\n1. Add this permission into the AndroidManifest:\n    * **android.permission.INTERNET**\n    \n2. Create an instance of **AIConfiguration**, specifying the access token, locale, and recognition engine. You can specify any recognition engine, since that value will not be used.\n3. Create an **AIDataService** instance using the configuration object.\n4. Create the empty **AIRequest** instance. Set the request text using the method **setQuery**.\n5. Send the request to the API.AI service using the method **aiDataService.request(aiRequest)**.\n6. Process the response.\n\nThe following example code sends a query with the text \"Hello\".\nFirst, it initialize `aiDataService` and `aiRequest` instances\n```java\nfinal AIConfiguration config = new AIConfiguration(ACCESS_TOKEN, \n    AIConfiguration.SupportedLanguages.English, \n    AIConfiguration.RecognitionEngine.System);\n\nfinal AIDataService aiDataService = new AIDataService(config);\n\nfinal AIRequest aiRequest = new AIRequest();\naiRequest.setQuery(\"Hello\");\n```\n\nThen it calls the `aiDataService.request` method. Please note, that you must call `aiDataService.request` method from background thread, using `AsyncTask` class, for example.\n```java\nnew AsyncTask\u003cAIRequest, Void, AIResponse\u003e() {\n    @Override\n    protected AIResponse doInBackground(AIRequest... requests) {\n        final AIRequest request = requests[0];\n        try {\n            final AIResponse response = aiDataService.request(aiRequest);\n            return response;\n        } catch (AIServiceException e) {\n        }\n        return null;\n    }\n    @Override\n    protected void onPostExecute(AIResponse aiResponse) {\n        if (aiResponse != null) {\n            // process aiResponse here\n        }\n    }\n}.execute(aiRequest);\n```\n\n## Getting results\nAfter implementing AIListener interface, you can get the response from api.ai inside your listener like this:\n\n```java\npublic void onResult(final AIResponse response) {\n   // Use the response object to get all the results\n}\n```\n\nHere is how to get different part of the result object:\n\n* Get the status\n\n   ```java\n   final Status status = response.getStatus();\n   Log.i(TAG, \"Status code: \" + status.getCode());\n   Log.i(TAG, \"Status type: \" + status.getErrorType());\n   ```\n   \n* Get resolved query\n\n   ```java\n   final Result result = response.getResult();\n   Log.i(TAG, \"Resolved query: \" + result.getResolvedQuery());\n   ```\n   \n* Get action\n\n   ```java\n   final Result result = response.getResult();\n   Log.i(TAG, \"Action: \" + result.getAction());\n   ```\n   \n* Get speech\n\n   ```java\n   final Result result = response.getResult();\n   final String speech = result.getFulfillment().getSpeech();\n   Log.i(TAG, \"Speech: \" + speech);\n   ```\n   \n* Get metadata\n\n   ```java\n   final Result result = response.getResult();\n   final Metadata metadata = result.getMetadata();\n   if (metadata != null) {\n     Log.i(TAG, \"Intent id: \" + metadata.getIntentId());\n     Log.i(TAG, \"Intent name: \" + metadata.getIntentName());\n   }\n   ```\n\n* Get parameters\n\n   ```java\n   final Result result = response.getResult();\n   final HashMap\u003cString, JsonElement\u003e params = result.getParameters();\n   if (params != null \u0026\u0026 !params.isEmpty()) {\n     Log.i(TAG, \"Parameters: \");\n     for (final Map.Entry\u003cString, JsonElement\u003e entry : params.entrySet()) {\n         Log.i(TAG, String.format(\"%s: %s\", entry.getKey(), entry.getValue().toString()));\n     }\n   }\n   ```\n    \n# \u003ca name=\"tutorial\" /\u003eTutorial\n\nThis section contains a detailed tutorial about creating new app and connect it to API.AI.\n\n## Create a new app\n\nFollow these steps to set up your environment and create new android app with API.AI integration:\n\n1. Create an API.AI agent with entities and intents, or use one that you've already created. See the API.AI documentation for instructions on how to do this. \n2. Open [Android Studio](https://developer.android.com/sdk/installing/studio.html). (Download it if you don't have it.)\n3. From the start screen (or **File** menu) , choose **New Project...**.\u003cbr/\u003e ![New Project](docs/images/NewProject.png)\n4. In the New Project dialog, fill **Application name** and **Company Domain**, then click **Next**.\u003cbr/\u003e ![New project dialog](docs/images/NewProjectDialog.png)\n5. Choose minimum SDK for project, minimum supported by API.AI SDK is **9 Gingerbread**. Click **Next**.\u003cbr/\u003e ![Min SDK](docs/images/MinSDK.png)\n6. Select **Blank Activity** and click **Next**.\n7. Enter the main activity name and click **Finish**.\n\n## Integrate with the SDK\n\nNext you will integrate with the SDK to be able to make calls. Follow these steps:\n\n1. Open **AndroidManifest.xml** under **app/src/main**. \n2. Just above the `\u003capplication\u003e` tag, add these line in order to give the app permission to access the internet and the microphone:\n\n    ```xml\n    \u003cuses-permission android:name=\"android.permission.INTERNET\"/\u003e\n    \u003cuses-permission android:name=\"android.permission.RECORD_AUDIO\" /\u003e\n    ```\n    \n3. Save **AndroidManifest.xml**.\n4. Next, you need to add a new dependency for the AI.API library. Right click on your module name (it should be _app_) in the Project Navigator and select **Open Module Settings**. Click on the **Dependencies** tab. Click on the **+** sign on the bottom left side and select **Library dependency**. \u003cbr/\u003e![Add dependency](docs/images/Dependencies.png)\n5. In the opened dialog search **ai.api**, choose **ai.api:sdk:2.0.5** item and append `@aar` to the end of library name (see image) then click OK.\u003cbr/\u003e ![Add dependency](docs/images/Dependencies2.png)\n    * Also you need to add dependencies of the SDK library : *com.android.support:appcompat-v7*, *com.google.code.gson:gson*, *commons-io:commons-io*. Add them in the same way.\n6. Open **MainActivity.java** under **app/src/main/java/com.example.yourAppName.app**, or whatever your package name is.\n7. Expand the import section and add the following lines to import the necessary API.AI classes:\n    \n    ```java\n    import ai.api.AIListener;\n    import ai.api.android.AIConfiguration;\n    import ai.api.android.AIService;\n    import ai.api.model.AIError;\n    import ai.api.model.AIResponse;\n    import ai.api.model.Result;\n    import com.google.gson.JsonElement;\n    import java.util.Map;\n    ```\n    \n## Create the user interface\n1. Open **activity_main.xml** under **app/src/main/res/layout**. This will open the layout in the designer.\u003cbr/\u003e![activity_main.xml in Designer](docs/images/LayoutDesigner.png)\n2. Select and delete the \"Hello World\" TextView.\n3. Drag a Button (under Widgets) to the top of the screen. Change the **id** property to \"listenButton\" and the **text** property to \"Listen\".\u003cbr/\u003e![Listen button](docs/images/ListenButton.png)\n4. Drag a Plain TextView (under Widgets) under the button. Expand it so that it covers the rest of the bottom of the screen. Change the **id** property to \"resultTextView\" and the **text** property to an empty string.\u003cbr/\u003e![Result TextView](docs/images/ResultViewText.png)\n6. Now return to the MainActivity.java file. Add three import statements to access our widgets:\n    \n    ```java\n    import android.view.View;\n    import android.widget.Button;\n    import android.widget.TextView;\n    ```\n    \n7. Create two private members in MainActivity for the widgets:\n   \n    ```java\n    private Button listenButton;\n    private TextView resultTextView;\n    ```\n    \n8. At the end of the OnCreate method, add these lines to initialize the widgets:\n    \n    ```java\n    listenButton = (Button) findViewById(R.id.listenButton);\n    resultTextView = (TextView) findViewById(R.id.resultTextView);\n    ```\n    \n## Create the AI Service and Listener\n\n1. Use the MainActivity as the class that will be called when events occur by having it implement the AIListener class. Replace the class declaration with this:\n    \n    ```\n    public class MainActivity extends ActionBarActivity implements AIListener {\n    ```\n    \n2. In the MainActivity class, create a private member for the **AIService** class named `aiService`.\n    \n    ```java\n    private AIService aiService;\n    ```\n    \n3. In the OnCreate method, add the following line to set up the configuration to use system speech recognition. Replace CLIENT_ACCESS_TOKEN with your client access token. \n    \n    ```java\n     final AIConfiguration config = new AIConfiguration(\"CLIENT_ACCESS_TOKEN\",\n            AIConfiguration.SupportedLanguages.English,\n            AIConfiguration.RecognitionEngine.System);\n    ```\n    \n    ![Api keys](docs/images/apiKeys.png)\n    \n4. Below this line, initialize the AI service and add this instance as the listener to handle events.\n    \n    ```java\n    aiService = AIService.getService(this, config);\n    aiService.setListener(this);\n    ```\n    \n5. Add method to start listening on the button click:\n    ```java\n    public void listenButtonOnClick(final View view) {\n        aiService.startListening();\n    }\n    ```\n    \n6. Return to activity_main.xml and click on the Listen button. In the properties pane, set the onClick property to listenButtonOnClick.\n7. Add the following method to show the results when the listening is complete:\n    \n    ```java\n    public void onResult(final AIResponse response) {\n        Result result = response.getResult();\n\n        // Get parameters\n        String parameterString = \"\";\n        if (result.getParameters() != null \u0026\u0026 !result.getParameters().isEmpty()) {\n            for (final Map.Entry\u003cString, JsonElement\u003e entry : result.getParameters().entrySet()) {\n                parameterString += \"(\" + entry.getKey() + \", \" + entry.getValue() + \") \";\n            }\n        }\n\n        // Show results in TextView.\n        resultTextView.setText(\"Query:\" + result.getResolvedQuery() +\n            \"\\nAction: \" + result.getAction() +\n            \"\\nParameters: \" + parameterString);\n    }\n    ```\n    \n8. Add the following method to handle errors:\n    \n    ```java\n    @Override\n    public void onError(final AIError error) {\n        resultTextView.setText(error.toString());\n    }\n    ```\n    \n9. Add the following empty methods to implement the AIListener interface:\n    ```java\n    @Override\n    public void onListeningStarted() {}\n\n    @Override\n    public void onListeningCanceled() {}\n\n    @Override\n    public void onListeningFinished() {}\n    \n    @Override\n    public void onAudioLevel(final float level) {}\n    ```\n    \n## Run the App\n1. Attach an Android device to your computer or have a virtual device ready.\n2. Make sure that your module is selected in the dropdown, and then click the Debug button.\u003cbr/\u003e![Debug button](docs/images/DebugButton.png)\n3. The app should now be running on your device or virtual device. Click the **Listen** button and then speak a phrase that will work with your intent. Wait a few seconds. The result should appear in the result TextView. \u003cbr/\u003e![Result](docs/images/AppScreenshot.png)\n\n# Feature examples\n\n## User specified contexts\n\nTo specify additional [contexts](http://api.ai/docs/getting-started/key-concepts.html#contexts) in the query you can use `RequestExtras` object.\n\nFirst create list of contexts you need:\n\n```java\nList\u003cAIContext\u003e contexts = new ArrayList\u003c\u003e();\ncontexts.add(new AIContext(\"firstContext\"));\ncontexts.add(new AIContext(\"secondContext\"));\n```\n\nThen create `RequestExtras` instance and use it for request\n\n```java\nRequestExtras requestExtras = new RequestExtras(contexts, null);\naiService.startListening(requestExtras);\n```\n\n## User specified entities\n\nTo specify user entities in the query you can use `RequestExtras` object.\n\nFirst create list of entities you need:\n\n```java\nfinal Entity myDwarfs = new Entity(\"dwarfs\");\nmyDwarfs.addEntry(new EntityEntry(\"Ori\", new String[] {\"Ori\", \"Nori\"}));\nmyDwarfs.addEntry(new EntityEntry(\"Bifur\", new String[] {\"Bofur\",\"Bombur\"}));\nfinal List\u003cEntity\u003e entities = Collections.singletonList(myDwarfs);\n```\n\nThen create `RequestExtras` instance and use it for request\n\n```java\nRequestExtras requestExtras = new RequestExtras(null, entities);\naiService.startListening(requestExtras);\n```\n\nAlso you can upload user entities with separate method\n\n```java\naiService.uploadUserEntities(entities);\n```\n\n## Bluetooth support\n\nDo these steps to make SDK work with Bluetooth devices:\n\n1. Create implementation of the [BluetoothController](https://github.com/api-ai/api-ai-android-sdk/blob/master/ailib/src/main/java/ai/api/util/BluetoothController.java) near your Application class\n    ```java\n    private class BluetoothControllerImpl extends BluetoothController {\n\n        public BluetoothControllerImpl(Context context) {\n            super(context);\n        }\n\n        @Override\n        public void onHeadsetDisconnected() {\n            Log.d(TAG, \"Bluetooth headset disconnected\");\n        }\n\n        @Override\n        public void onHeadsetConnected() {\n            Log.d(TAG, \"Bluetooth headset connected\");\n\n            if (isInForeground() \u0026\u0026 !bluetoothController.isOnHeadsetSco()) {\n                bluetoothController.start();\n            }\n        }\n\n        @Override\n        public void onScoAudioDisconnected() {\n            Log.d(TAG, \"Bluetooth sco audio finished\");\n            bluetoothController.stop();\n\n            if (isInForeground()) {\n                bluetoothController.start();\n            }\n        }\n\n        @Override\n        public void onScoAudioConnected() {\n            Log.d(TAG, \"Bluetooth sco audio started\");\n        }\n\n    }\n    ```\n2. Add to your `Application` class integer field to count Activities and `BluetoothController` class implementation for Bluetooth management\n    ```java\n    private int activitiesCount;\n    private BluetoothControllerImpl bluetoothController;\n    ```\n\n3. Add helper methods to your `Application` class\n    ```java\n    protected void onActivityResume() {\n        if (activitiesCount++ == 0) { // on become foreground\n            bluetoothController.start();\n        }\n    }\n\n    protected void onActivityPaused() {\n        if (--activitiesCount == 0) { // on become background\n            bluetoothController.stop();\n        }\n    }\n\n    private boolean isInForeground() {\n        return activitiesCount \u003e 0;\n    }\n    ```\n\n4. You need to call this methods from `onPause` and `onResume` of every Activity, it can be solved with base class for all your activities\n    ```java\n    public class BaseActivity extends ActionBarActivity {\n\n        private AIApplication app;\n\n        private static final long PAUSE_CALLBACK_DELAY = 500;\n\n        private final Handler handler = new Handler();\n        private Runnable pauseCallback = new Runnable() {\n            @Override\n            public void run() {\n                app.onActivityPaused();\n            }\n        };\n\n        @Override\n        protected void onCreate(Bundle savedInstanceState) {\n            super.onCreate(savedInstanceState);\n            app = (AIApplication) getApplication();\n        }\n\n        @Override\n        protected void onResume() {\n            super.onResume();\n            app.onActivityResume();\n        }\n\n        @Override\n        protected void onPause() {\n            super.onPause();\n            handler.postDelayed(pauseCallback, PAUSE_CALLBACK_DELAY);\n        }\n    }\n    ```\n\nA complete example can be found in the [Sample Application](https://github.com/api-ai/api-ai-android-sdk/tree/master/apiAISampleApp/src/main/java/ai/api/sample).\n\n# \u003ca name=\"troubleshooting\" /\u003eTroubleshooting\n\n* If you get an error when trying to install app that says \"INSTALL_FAILED_OLDER_SDK\", then check you have Android SDK 19 and build tools 19.1 installed.\n\n## How to make contributions?\nPlease read and follow the steps in the [CONTRIBUTING.md](CONTRIBUTING.md).\n\n## License\nSee [LICENSE](LICENSE).\n\n## Terms\nYour use of this sample is subject to, and by using or downloading the sample files you agree to comply with, the [Google APIs Terms of Service](https://developers.google.com/terms/).\n\nThis is not an official Google product.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdialogflow%2Fdialogflow-android-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdialogflow%2Fdialogflow-android-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdialogflow%2Fdialogflow-android-client/lists"}