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>
Related
I am developing a Huawei custom Theme. I was trying to change some Google apps (Documents, Sheets and Slides) icons. So I used as address their package name e.g. com.google.android.apps.docs.editors.slides
Since it didn't work, I tried with some activities, found in the manifest file, but no one worked yet. (for example com.google.android.apps.editors.homescreen.HomescreenActivity, which is the first one that appears when I open Slides);
So the question is:
is there a way to identify which is the main activity, nay, which is the activity who defines app icon?
Usually, the main activity declares the following intent filters (documentation) in order to indicate for the system that this activity is Main and is a launcher activity:
<activity android:name=".ActivityClassName">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
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>
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 have a button in my app. When it is pressed I call the onSearchRequested() method. When this is called the stock search box comes up so the user can type some junk in there. When they press "Go" I need the results returned back to my application but instead the stock browser is opened and a google search is performed. How can I tell it to return the results to my application instead.
I've tried these items in my manifest.xml file:
<meta-data android:name="android.app.default_searchable"
android:value=".MainActivity" />
<activity android:name=".MainActivity"
android:launchMode="singleTop"
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
I've also tried to capture the result in my onCreate with this:
Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction()))
This is covered fairly well in the documentation. In particular, you are missing the searchable <meta-data> element (and, presumably, the corresponding XML file). Here is a sample project showing the use of search within an application.
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…