Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development > Developer 101

Developer 101 101 Tutorials



Reply
 
LinkBack Thread Tools
Old December 18th, 2011, 08:18 PM   #1 (permalink)
New Member
 
Join Date: Dec 2011
Posts: 2
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Need loop code or ?

I have problem with voice recognition code, works first part but then uses 1st 'results' in the google search method... ugh..

code:

if (results.contains("play")){


Handler handler4 = new Handler();
handler4.postDelayed(new Runnable() {
public void run() {

mTts.speak("Play What?", TextToSpeech.QUEUE_FLUSH, null);
}
}, 1000);

Handler handler5 = new Handler();
handler5.postDelayed(new Runnable() {
public void run() {

Intent g = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

g.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
g.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak UP!");
g.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);


final ArrayList<String> results1 = data.getStringArrayListExtra(RecognizerIntent.EXTR A_RESULTS);
startActivityForResult(g, check);

Handler handler4 = new Handler();
handler4.postDelayed(new Runnable() {
public void run() {

Intent sgoogle = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.com/search?q=%22"+results1+"%22"));
startActivityForResult(sgoogle, check);
}
}, 12000);

}
}, 5000);

It is suppose to react to word 'play' which it does, then TTS ask "Play what?", which it does.. and then open recognizer, which it does.. then take results to google search, which is where its broken.. because it uses the 1st results of 'play' ..

Thank you in advance.
Flinx

Flinx is offline  
Reply With Quote
Sponsors
Old December 18th, 2011, 09:11 PM   #2 (permalink)
Premium Member
 
Join Date: Oct 2011
Location: Sydney, Australia
Posts: 193
 
Device(s): Galaxy Nexus GSM
Thanks: 2
Thanked 37 Times in 33 Posts
Default

I think you're doing too much in one place. As I understand it, startActivityForResult will not block while the activity runs. It will return immediately. You need to wait for your onActivityResult(int, int, Intent) to be called.

Take a look at Starting Activities and Getting Results.
jiminaus is offline  
Reply With Quote
Reply

Bookmarks

Tags
android, java


Go Back   Android Forums > Android Development > Application Development > Developer 101 User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 08:19 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo