willblaschko / AlexaAndroid

A library and sample app to abstract access to the Amazon Alexa service for Android applications.
GNU General Public License v2.0
280 stars 133 forks source link

How to get the response in text format besides Audio response? #149

Open chowdary60 opened 6 years ago

chowdary60 commented 6 years ago

hello @willblaschko , @wantitmore ,@prasannakumark

I am trying to display the weather information on device UI. for that when we ask question to Alexa, it supposed to give response of type "Speak " and "RenderTemplate". The RenderTemplate directive will have the weather information in text format.

when i check the AvsResponse i am getting only AvsSpeakItem only .How to get the "Render " object which the actual information about the weather to show it in User interface. any Ideas please?

RayHuangDev commented 6 years ago

You must check your alexa products first, when you create a new product. there have a section "capability" need select "Display Cards With Media" then you will get "RenderTemplate" data. https://drive.google.com/file/d/1qJJm_FR5T3qBdSpYk9w-4UJHdKosjG5e/view

tatasadi commented 6 years ago

@RayHuangDev I've done that. In which class can we then get the RenderTemplate? By the way your link does not work!

RayHuangDev commented 6 years ago

@Ehsanta83 you can copy link and paste on browser, it's a pic about alexa product setting page BTW, this sample has no AvsRenderTemplate class, need create by your own

tatasadi commented 6 years ago

@RayHuangDev Do you have an example of creating it on your own which you can share with us? It would be much appreciated.

RayHuangDev commented 6 years ago

@Ehsanta83 here is code below, you can change parameters by your own

public class AvsRenderTemplateItem extends AvsItem { private String mHeaderName; private Payload mPayload;

public AvsRenderTemplateItem(String token, String headerName, Payload payload) {
    super(token);

    mHeaderName = headerName;
    mPayload = payload;
}

public String getmHeaderName() {
    return mHeaderName;
}

public Payload getPayload() {
    return mPayload;
}

}

tatasadi commented 6 years ago

@RayHuangDev Thank you for sharing the code. How do you use it? I mean in this project.

RayHuangDev commented 6 years ago

add this class in "interfaces" folder such as link below: https://github.com/willblaschko/AlexaAndroid/tree/master/libs/AlexaAndroid/src/main/java/com/willblaschko/android/alexa/interfaces

you can use in BaseActivity->checkQueue()-> else if (current instanceof AvsRenderTemplateItem ){ ... }

https://github.com/willblaschko/AlexaAndroid/blob/master/app/src/main/java/com/willblaschko/android/alexavoicelibrary/BaseActivity.java