Search code examples
androidiotalexa-skills-kitalexa-voice-service

How to get voice query to my app with Amazon Voice Service or Alexa


While developing an IoT device integration with Android app I'm stuck at this problem.

What I wish to achieve is to talk to my app, for example, "Alexa, What is the temperature inside the cooker?". For this info to retrieve, I have an android app connected to smart cooker via bluetooth and the app than can read the temperature info from cooker.

Now how do I get the query in my android app and how can I return my response as "The current temperature in cooker is 100 degree celsius". and alexa could verbalize it for me.

Here is what I've done so far.

  1. I created an account with amazon developer console
  2. Registered my app there and copied API key into my android project
  3. Added their lib in my android project
  4. Used Login With Amazon service to get the accessToken

    requestContext = RequestContext.create(this)
    requestContext.registerListener(object : AuthorizeListener() {
        override fun onSuccess(authorizeResult: AuthorizeResult) {
            accessToken = authorizeResult.accessToken
            Timber.d("Access Token: %s", accessToken)
        }
    
        override fun onCancel(auth: AuthCancellation?) {
            Timber.e(auth?.description)
        }
    
        override fun onError(error: AuthError) {
            Timber.e(error, error.localizedMessage)
        }
    })
    
    signInBtn.setOnClickListener {
        AuthorizationManager.authorize(
            AuthorizeRequest.Builder(requestContext)
                .addScopes(ProfileScope.profile(), ProfileScope.postalCode())
                .build()
        )
    }
    

Here is the manifest's relevant declarations

<activity android:name="com.amazon.identity.auth.device.workflow.WorkflowActivity"
    android:theme="@android:style/Theme.NoDisplay"
    android:allowTaskReparenting="true"
    android:launchMode="singleTask">
    <intent-filter>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <!-- android:host must use the full package name found in Manifest General Attributes -->
        <data android:host="${applicationId}" android:scheme="amzn"/>
    </intent-filter>
</activity>

I've been following this documentation.

What do I have to do to get the query in my application to process and return the result? or is it possible at all?


Solution

  • You need to create a Smart home skill to do it, the way you need to go forward is

    1. create a smart home skill , reference documentation here

    2. Once you have created a smarthome skill(you would have created a backend server in the process) and the user has enabled the skill in his Alexa account after this whenever the user asks "Alexa, What is the temperature inside the cooker?" you will get a directive request to your server , which you can then route it to the android app and have the android app send response to the AVS directly or through your server .