Comments (5)
Here's my MainActivity Java.
`package com.blah;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
//API
import ai.api.AIConfiguration;
import ai.api.AIListener;
import ai.api.AIService;
import ai.api.model.AIError;
import ai.api.model.AIResponse;
import ai.api.model.Result;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.gson.JsonElement;
import java.util.Map;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity implements AIListener {
//public class MainActivity extends AppCompatActivity implements AIListener {
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
//API
private Button listenButton;
private TextView resultTextView;
private AIService aiService;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//API
listenButton = (Button) findViewById(R.id.listenButton);
resultTextView = (TextView) findViewById(R.id.resultTextView);
final AIConfiguration config = new AIConfiguration("22c120252de84d3c87e415e706e4f8d7",
"fc32ea99-9efa-49b7-b465-b0b47ede3923", AIConfiguration.SupportedLanguages.English,
AIConfiguration.RecognitionEngine.System);
aiService = AIService.getService(this, config);
aiService.setListener(this);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
//
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
protected void onPause() {
super.onPause();
// use this method to disconnect from speech recognition service
// Not destroying the SpeechRecognition object in onPause method would block other apps from using SpeechRecognition service
listenButton.pause();
}
@Override
protected void onResume() {
super.onResume();
// use this method to reinit connection to recognition service
listenButton.resume();
}
//API
public void listenButtonOnClick(final View view) {
aiService.startListening();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onError(final AIError error) {
resultTextView.setText(error.toString());
}
@Override
public void onAudioLevel(float level) {
}
@Override
public void onListeningStarted() {
}
@Override
public void onListeningCanceled() {
}
@Override
public void onListeningFinished() {
}
@Override
public void onResult(final AIResponse response) {
Result result = response.getResult();
// Get parameters
String parameterString = "";
if (result.getParameters() != null && !result.getParameters().isEmpty()) {
for (final Map.Entry<String, JsonElement> entry : result.getParameters().entrySet()) {
parameterString += "(" + entry.getKey() + ", " + entry.getValue() + ") ";
}
}
// Show results in TextView.
resultTextView.setText("Query:" + result.getResolvedQuery() +
"\nAction: " + result.getAction() +
"\nParameters: " + parameterString);
}
@Override
public void onStart() {
super.onStart();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client.connect();
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"Main Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app activity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://hhapi.commando.blah.com/main"),
// TODO: Make sure this auto-generated app deep link URI is correct.
Uri.parse("android-app://com.blah/http/hhapi.commando.blah.com/main")
);
AppIndex.AppIndexApi.start(client, viewAction);
}
@Override
public void onStop() {
super.onStop();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"Main Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app activity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://hhapi.commando.blah.com/main"),
// TODO: Make sure this auto-generated app deep link URI is correct.
Uri.parse("android-app://com.blah/http/blah.commando.blah.com/main")
);
AppIndex.AppIndexApi.end(client, viewAction);
client.disconnect();
}
}
`
from dialogflow-android-client.
Hi, @aliyah
Could you please show me the activity_main
layout?
Also, could you please attach log output from the app?
Thanks!
from dialogflow-android-client.
Because of no comments for a long time I'll close the ticket...
from dialogflow-android-client.
-__-
from dialogflow-android-client.
I am not getting api.ai.model class after adding ai.api:sdk:2.0.5@aar' in dependency
from dialogflow-android-client.
Related Issues (20)
- sending payload from V1 SDK HOT 1
- AIButton fails to initialize after following instructions in Integration.md
- TTS HOT 3
- end_conversation
- On account of using Hindi in DialogFlow
- voice rocoginition took same text in multiple time
- Quick Reply
- Hii Any client for v2 for android HOT 1
- HttpClient cannot be used in the same project with dialogflow HOT 1
- Mic button is not working in android with web demo integration HOT 1
- How to migrate to Dialogflow API V2 and the v2 client library for android client? HOT 11
- Can not getting card or images?
- How to send recorded audio in AIService or get record audio through AIListener of dialogflow android
- URLs to be allowed when using dialogflow-android in restricted network. . . HOT 1
- Raw JSON is there in the console but not getting response in the console nor device
- Language support
- AIService Error
- Intent fulfillments HOT 2
- Authorization failed. Please check your access keys. Error Issues
- Hindi not supported
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dialogflow-android-client.