I am trying to gather as much information as I can about creating a search interface in Android Studio. I am working with developer.android.com and have a question about using the search interface.
I quote:
<application ... >
<!-- this is the searchable activity; it performs searches -->
<activity android:name=".SearchableActivity" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<!-- this activity enables the search dialog to initiate searches
in the SearchableActivity -->
<activity android:name=".OtherActivity" ... >
<!-- enable the search dialog to send searches to SearchableActivity -->
<meta-data android:name="android.app.default_searchable"
android:value=".SearchableActivity" />
</activity>
...
"If you want every activity in your application to provide the search dialog, insert the above meta-data element as a child of the application element, instead of each activity. This way, every activity inherits the value, provides the search dialog, and delivers searches to the same searchable activity."
I don't understand the first sentence, unfortunately. What do I have to do exactly in order to have my search dialog in every activity. In this code example, we only have the search dialog in one activity. Can anyone show me using the code above, how to insert meta-data as a child of the application element in my AndroidManifest.xml?
Thank you.
It just describes an easy way of doing things.
You add the <meta-data> element to every activity that you want to have this behaviour of providing a serach dialog. However, if all your activities have this behaviour, instead of adding the <meta-data> element to all of them, you can just add it to the <application> and it'll work as if you added it to all <activity>s. Just add it to your application like:
<application
android:name=".MyApp"
android:icon="#drawable/ic_launcher">
<meta-data android:name="android.app.default_searchable"
android:value=".SearchableActivity" />
...
</application>
Related
I am having a hard time figuring out the documentation on creating a search Interface.
My main activity contains the search widget on the app bar but when I perform a search query it does not launch the Searchable Activity; responsible for displaying the results.
Below is my manifest file for the SearchbaleActivity and MainActivity
<activity
android:name=".activities.SearchableActivity"
android:exported="false"
android:label="#string/title_activity_searchable"
android:theme="#style/Theme.MoveApplication.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity
android:name=".activities.MainActivity"
android:exported="false" >
</activity>
Should my intent-filter and meta-data attributes be in my MainActivity or SearchableActivity?
And even so, my SearchableActivity should launch despite not handling the query, right?
My Android skills are not that great so i'll appreciate a vivid explanation with examples
I am trying to use the Search Manager from Android.
In fact, I have an activity where I am calling
onSearchRequested()
Then, I am using in the same activity this function to get the search string:
// Get the intent, verify the action and get the query
Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
}
The problem is the next: When i am clicking to the search button, I am opening a new activity and i would like to stay on the same and do some searches. So, my goal is to avoid the new activity opening when I click to the search button.
Thank you.
The solution consists to reuse the developpers example http://developer.android.com/guide/topics/search/search-dialog.html
The important thing is to create 2 activities, one for searches and one other for displaying the results.
In the manifest, use this code:
<application ... >
<!-- this is the searchable activity; it performs searches -->
<activity android:name=".SearchableActivity" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<!-- this activity enables the search dialog to initiate searches
in the SearchableActivity -->
<activity android:name=".OtherActivity" ... >
<!-- enable the search dialog to send searches to SearchableActivity -->
<meta-data android:name="android.app.default_searchable"
android:value=".SearchableActivity" />
</activity>
...
use in Manifest
<activity android:name="BrowseItems" android:label="#string/browseitems"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/itemsearchable" />
</activity>
i have one activity in my android application in which a list of orders is populated. I want to implement a search functionality on this activity so that user can search for particular order.
I have read about the search box facility provided by adding a searchable.xml file in the application but I am not able to make it work for me?
I just want to add a search box in the activity and search for specific data in database.
How can I do this?
#VNVN I would agree - I would review the developer guide. http://developer.android.com/guide/topics/search/search-dialog.html
You will need to make your activity search-able in the AndroidMainfest.xml file
<activity android:name=".MySearchableActivity" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
You are probably missing creating a SearchableActivity. http://developer.android.com/guide/topics/search/search-dialog.html#SearchableActivity
I'm running into an issue with the Quick Search Bar that I'm hoping someone can help me with.
My application includes a Searchable activity used to provide search behavior within my application. That search activity is designed to trigger a separate Intent when the search item is clicked on so as to cause a different Activity to handle the viewing. When used within the application, the search behavior works perfectly every time.
My application also includes a ContentProvider used to provide search suggestions and is also configured to allow use in the Quick Search Bar. When used within the application itself, use of the search suggestions works fine every time it is used. When triggered from the QSB, the initial search suggestion brings up the viewing activity just as it should. After that point, however, any use of the search suggestions from within the application (i.e. bringing up the search and selecting a search suggestion) fails to trigger the viewing application. In fact, I've put debug statements in every single "onXXX()" method within the Searchable activity and I never see any of them get triggered. On the flip side, when I trigger a standard search at that same point (i.e. enter a query string and hit enter, rather than navigating to a search suggestion), the search dialog comes up, as expected, and selecting an item from that list successfully triggers my application.
I'm currently at a loss trying to determine why this would be occurring. Any ideas
As as some additional information, my manifest contains the following in regards to the searchable activity (".activity.SearchableActivity"), the suggestions provider (".content.TestSuggestionProvider") and the activity used to display the content (".activity.TestDisplayActivity"):
<activity
android:name=".activity.TestDisplayActivity"
android:label="#string/app_name"
android:launchMode="singleTask"
android:finishOnTaskLaunch="true"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.app.default_searchable" android:value=".activity.SearchableActivity" />
</activity>
<activity
android:name=".activity.SearchableActivity"
android:launchMode="singleTop"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.searchable" android:resource="#xml/searchable"/>
</activity>
<provider
android:name=".content.TestSuggestionProvider"
android:authorities="com.test.provider.suggest"
android:syncable="false"
/>
And the following is the XML used to further define the settings of the searchable activity:
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="#string/search_app_label"
android:hint="#string/search_app_hint"
android:searchSettingsDescription="#string/search_app_settings_description"
android:includeInGlobalSearch="true"
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
android:searchSuggestAuthority="com.test.provider.suggest"
android:searchSuggestIntentAction="android.intent.action.VIEW">
</searchable>
Any thoughts? At the moment I'm at a complete loss…
Right now I'm adding
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.searchable" android:resource="#xml/searchable" />
to every single <activity> in the AndroidManifest.xml, receive the Intent in each activity and forward the search string to one singleTop activity that actually performs the search (via HTTP/JSON) and displays the results in a list.
I'm wondering if there's a way how I can set-up the AndroidManifest.xml, so that search is activated in each activity within my application, but the search string will get forwarded from Android's search box directly to my singleTop SearchResults_Activity instead of going the way through validating events in each activity and then forwarding the search string.
The answer to that is actually available in the SearchManager documentation, in the MetaData chapter.
Activities which are part of a
searchable application, but don't
implement search itself, require a bit
of "glue" in order to cause them to
invoke search using your searchable
activity as their primary context. If
this is not provided, then searches
from these activities will use the
system default search context.
<application>
<meta-data android:name="android.app.default_searchable"
android:value=".MySearchActivity" />
<!-- followed by activities, providers, etc... -->
</application>