Add AI Voice Assistant to Android Apps

Create a new project with Basic Activity
Naming the Project
Create an empty project
Add predefined scripts
dependencies {
// Add Alan dependency
implementation 'app.alan:sdk:4.12.0'
Module level build.gradle
app:button_horizontal_align="right" />
public class MainActivity extends AppCompatActivity {
private ActivityMainBinding binding;
private static final String SDK_KEY = "YOUR SDK KEY"; @Override
protected void onCreate(Bundle savedInstanceState) {
... AlanButton alanButton = binding.alanButton;
AlanConfig config = AlanConfig.builder()
Hello world
intent('What can you do?', p => {'I can add a task and read them for you');
});intent('Say hurrah', p => {'Hurrah!');
Custom voice command

“Contain as much code in respective methods so that it gets easier to add voice in later steps”

//In Alan console
intent('(Go|take me) back', p => {'Sure');{ commandName: "go_back" });
});intent('Add a todo task (named|with title|) $(TASK_TITLE* (.+))', p => {'Adding the task');{ commandName: "add_todo", title: p.TASK_TITLE.value });
Alan Studio console
AlanCallback alanCallback = new AlanCallback() {
/// Handle commands from Alan Studio
public void onCommand(final EventCommand eventCommand) {
try {
JSONObject command = eventCommand.getData();
1 //data object is the JSON Object returned in method
JSONObject data = command.getJSONObject("data");
String commandName = data.getString("command");
//based on commandName we can perform different tasks
executeCommand(commandName, data);
} catch (JSONException e) {
Log.e("AlanButton", e.getMessage());
private void executeCommand(String commandName, JSONObject data) {
if (commandName.equals("go_back")) {
onBackPressed(); //android lifecycle method
if (commandName.equals("log_out")) {
if (commandName.equals("add_todo")) {
try {
String title = data.getString("title");
} catch (JSONException e) {
Log.e("AlanButton", e.getMessage());
alanButton.playText("I'm sorry I'm unable to do this at the moment");
}private void logOut() {
//code to log out
}private void addTodoItem(String title) {
//code to add a Todo Item

What else can you do with Alan?

//Alan script
projectAPI.greetUser = function(p, param, callback) {
p.userData.nameOfUser = param.userName;`Hey ${p.userData.nameOfUser}, this is Alan. The voice assistant for Todo app. Here, you can store your daily tasks and prioritize them`);
public void greetUser(String name) {
binding.alanButton.activate();//parameters to be passed
JSONObject object = new JSONObject();
try {
object.put("userName", name);
binding.alanButton.callProjectApi("greetUser", object.toString());
} catch (JSONException e) {
private void speakText(String text, AlanButton alanButton) {
//if the function is written outside
//pass alanButton in parameter as shown and instead write
//alanButton.playText(text); binding.alanButton.playText(text);
Handler Methods

Don’t forget to give us your 👏 !



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store