Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement Voice search to SearchView

I want to add voice search function to my application. I'm populating a SearchView in SherlockActivity. But I can't find a solution to add voice search function to SearchView object.

Can you please give an advice, what do I need to do?

Code below :

    public class MainActivity extends SherlockActivity {
        private SlidingMenu slidingMenu;
        private SlidingMenu slidingMenuRight;
        private String mFilterArrays[];
        public long lastScrollTime=0; /** En son kaydırma ne zaman yapıldı*/
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    }   

        public boolean onCreateOptionsMenu(Menu menu) {

                    //Create the search view
                    SearchView searchView = new SearchView(getSupportActionBar().getThemedContext());
                    searchView.setQueryHint("Search...");


                    menu.add("Search")
                        .setIcon(R.drawable.ic_search_inverse)
                        .setActionView(searchView)
                        .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
                        return true;
    }
}

Mainfest

<activity
    android:name="com.paea.bcp.MainActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="com.paea.bcp.MainActivity" />
        <category android:name="android.intent.category.DEFAULT" />
        <action android:name="android.intent.action.SEARCH" />                
    </intent-filter>
</activity>
like image 351
fobus Avatar asked Jul 24 '13 22:07

fobus


People also ask

How do you implement voice search?

Open the Google website on your desktop computer and you'll find a little microphone icon embedded inside the search box. Click the icon, say something and your voice is quickly transcribed into words.

What is Voice Search app used for?

How do you use Google Voice Search? Android Devices: Android users can turn on Google Voice Search anytime saying “OK Google“. You can use it to give voice commands to the device, find any information, and get directions.

What is voice search and control?

Voice search is a technology that allows the user to use a voice command to perform a search on the Internet, a website or an application. The result of advances in speech recognition, this feature first appeared on smartphones, making it possible to replace the search bar.

How does Google Search by voice work?

It works through the automatic speech recognition (ASR) system that transforms voice signal into text. Then search engines like Google use the text as if it's a typical search query and proceed with what they do best—matching the search query with the right results.


1 Answers

In your res/xml folder, you should have a searchable file (usually called searchable.xml).

Within the <searchable /> element in that file, you should add this attribute:

android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"

There are other voice-related attributes (currently voicePromptText, voiceLanguageModel and voiceLanguage) which are all described here.

like image 124
ban-geoengineering Avatar answered Sep 28 '22 18:09

ban-geoengineering