Integrating Chatbot in Android App
Requirements
- Android Studio
- Minimum Android SDK Version: 15
- Compile SDK Version: 29
- Targeted SDK Version: 29
Integrating SDK
Download AmplifyReach Android SDK from AmplifyReach Dashboard -> Channels -> Android SDK -> Download Tab.
Please follow the instruction to add build Dependencies: https://developer.android.com/studio/build/dependencies.html#library_dependency_configurations
Framework
- archatbotsdk-release.aar: A Library/Module to integrate AmplifyReach Chatbot in Android app.
The following data is required for completing AmplifyReach Chatbot integration
- clientId: client identification number (Long)
- botId: bot identification number (String)
- authToken: authentication token (String)
- host: host server name provided by AmplifyReach example: “apps.amplifyreach.com”
- icon: you can pass header image.
Permissions
The following permission are required for SDK integration
- INTERNET
- ACCESS_NETWORK_STATE
AndroidManifest.xml
<uses-permission android:name=”android.permission.INTERNET” />
<uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE” />
<uses-permission android:name=”android.permission.RECORD_AUDIO” />
<uses-permission android:name=”android.permission.MODIFY_AUDIO_SETTINGS” />
<uses-permission android:name=”android.permission.READ_EXTERNAL_STORAGE” />
<uses-permission android:name=”android.permission.MANAGE_DOCUMENTS” />
Activity
To launch the AmplifyReach Chatbot through Android Activity, please following the below steps.
- Declare ARActivity in AndroidManifest.xml. This activity is present in the ARChatSDK.
AndroidManifest.xml
<activity android:name=”ar.amplifyreach.archatbotsdk.ARActivity”
android:configChanges=”orientation|screenSize”></activity>
Load chat widget in new activity using following code snippet
... button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //This is code for Activity Integration Intent intent = new Intent(MainActivity.this, ARActivity.class); Bundle bundle = new Bundle(); //set host server bundle.putString("host","chat.amplifyreach.com"); //Set client ID bundle.putLong("clientId",CLINET_ID); //Set Bot ID bundle.putString("botId",BOT_ID); //set ActionBar icon bundle.putInt("icon",R.drawable.header_icon); //set Authentication Token bundle.putString("authToken",AUTH_TOKEN); intent.putExtras(bundle); MainActivity.this.startActivity(intent); } });
To get permission add following code snippet in your main activity.
private void requestPermission() { ActivityCompat.requestPermissions(this, new String[] {RECORD_AUDIO, MODIFY_AUDIO_SETTINGS,MANAGE_DOCUMENTS, READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE); }