⚠️ This repository is deprecated⚠️ We are no longer maintaining an Android library for Site Search. However, you can still build excellent native and mobile web experiences with Site Search APIs and clients. Thank you! - Elastic
A first-party Android library to add Elastic Site Search to Android applications.
Contents
Getting started 🐣
Note: This client has been developed for the Swiftype Site Search API endpoints only. You may refer to the Swiftype Site Search API Documentation for additional context.
- Import SwiftypeAndroid into your workspace.
- In the properties for your application select 'Android' and add the imported project as a library
- Choose a search activity:
- If your Swiftype search engine is crawler-based or WordPress-based and you would like to display results in a web view, use WebSearchActivity.
- If you have an API-based engine, or would like different result display behavior, extend SearchActivity and create a custom ShowDetailsFragment to present the results.
- Add the search activity to your AndroidManifest.xml (example for WebSearchActivity):
<activity
android:name="com.swiftype.android.search.webbased.WebSearchActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateAlwaysHidden"
android:exported="false"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
- Make it the default search activity for your application by adding the following lines to your main activity:
<meta-data
android:name="android.app.default_searchable"
android:value="com.swiftype.android.search.webbased.WebSearchActivity" />
- Copy
/res/values/swiftype_config.xml
and/res/values/colors.xml
(if you use a light theme) from SwiftypeAndroid. You must set the values forsearch_content_provider_authority
andengine_key
. - Copy
/res/xml/searchable.xml
from SwiftypeAndroid to your project. - Add
android:configChanges="orientation|screenSize"
to the application attributes inAndroidManifest.xml
. - Add the search provider and service to your
AndroidManifest.xml
:
<provider
android:exported="false"
android:authorities="@string/search_content_provider_authority"
android:name="com.swiftype.android.search.backend.SearchContentProvider" />
<service
android:name="com.swiftype.android.search.backend.SearchService" />
- Add Internet permissions to your
AndroidManifest.xml
:
<uses-permission android:name="android.permission.INTERNET" />
- Use a SearchView or the SearchDialog to start a search. For an example, look at our SwiftypeAndroidExample repository. More information can be found in the Android Documentation.
FAQ 🔮
Where do I report issues with the client?
If something is not working as expected, please open an issue.
Where can I learn more about Site Search?
Your best bet is to read the documentation.
Where else can I go to get help?
You can checkout the Elastic Site Search community discuss forums.
Contribute 🚀
We welcome contributors to the project. Before you begin, a couple notes...
- Before opening a pull request, please create an issue to discuss the scope of your proposal.
- Please write simple code and concise documentation, when appropriate.
License 📗
Thank you to all the contributors!