android TV-Making TV Apps Searchable,Searching within TV Apps
> Making TV Apps Searchable
Android TV uses the Android search
interface to retrieve content data from installed apps and deliver search results to the user. Your app's content data can be included with these results, to give the user instant
access to the content in your app.
Your app must provide Android TV with the data fields from which it generates suggested search results as the user enters characters in the search dialog. To do that, your app
must implement a Content Provider that
serves up the suggestions along with a searchable.xml
configuration
file that describes the content provider and other vital information for Android TV. You also need an activity that handles the intent that fires when the user selects a suggested search result. All of this is described in more detail in Adding
Custom Suggestions.
The SearchManager
describes
the data fields it expects by representing them as columns of an SQLite database. Regardless of your data's format, you must map your data fields to these columns, usually in the class that accessess your content data.
>The search framework requires the following columns:
SUGGEST_COLUMN_TEXT_1
SUGGEST_COLUMN_CONTENT_TYPE
SUGGEST_COLUMN_PRODUCTION_YEAR
SUGGEST_COLUMN_DURATION
res/xml/searchable.xml
file
to configure the search suggestions settings. It inlcudes the android:searchSuggestAuthority
attribute
to tell the system the namespace of your content provider. This must match the string value you specify in the android:authorities
attribute
of the <provider>
element
in your AndroidManifest.xml
file.
Along with the intent action, your app must provide the intent data, which you specify with theandroid:searchSuggestIntentData
attribute.
Also, note the android:searchSuggestSelection=" ?"
attribute which specifies the value passed as theselection
parameter of the query()
method
where the question mark (?
) value is replaced with the query text.
Finally, you must also include the android:includeInGlobalSearch
attribute
with the value "true"
. Here is an example searchable.xml
file:
<searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/search_label" android:hint="@string/search_hint" android:searchSettingsDescription="@string/settings_description" android:searchSuggestAuthority="com.example.android.tvleanback" android:searchSuggestIntentAction="android.intent.action.VIEW" android:searchSuggestIntentData="content://com.example.android.tvleanback/video_database_leanback" android:searchSuggestSelection=" ?" android:searchSuggestThreshold="1" android:includeInGlobalSearch="true" > </searchable>
When the user selects the link for your app, identified by the "Available On" button in the details screen, the system launches the activity which handles the ACTION_VIEW
(set
as android:searchSuggestIntentAction
with the value "android.intent.action.VIEW"
in
the searchable.xml
file).
You can also set up a custom intent to launch your activity, and this is demonstrated in the Android
Leanback sample app. Note that the sample app launches its own LeanbackDetailsFragment
to show the details for the selected media, but you should launch the activity that plays the media immediately to save the user another click
or two.
>Searching within TV Apps
>Users frequently have specific content in mind when using a media app on TV. If your app contains a large catalog of content, browsing for a specific title may not be the most efficient way for users to find what they are looking for. A search interface can help your users get to the content they want faster than browsing.
When you use the BrowseFragment
class for a media browsing interface,
you can enable a search interface as a standard part of the user interface. The search interface is an icon that appears in the layout when you setView.OnClickListener
on
the BrowseFragment
object. The following sample code demonstrates
this technique.
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.browse_activity); mBrowseFragment = (BrowseFragment) getFragmentManager().findFragmentById(R.id.browse_fragment); ... mBrowseFragment.setOnSearchClickedListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(BrowseActivity.this, SearchActivity.class); startActivity(intent); } }); mBrowseFragment.setAdapter(buildAdapter()); }> When a user selects the search icon, the system invokes a search activity via the defined intent. Your search activity should use a linear layout containing a
SearchFragment
.
This fragment must also implement theSearchFragment.SearchResultProvider
interface
in order to display the results of a search.
public class MySearchFragment extends SearchFragment implements SearchFragment.SearchResultProvider { private static final int SEARCH_DELAY_MS = 300; private ArrayObjectAdapter mRowsAdapter; private Handler mHandler = new Handler(); private SearchRunnable mDelayedLoad; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter()); setSearchResultProvider(this); setOnItemClickedListener(getDefaultItemClickedListener()); mDelayedLoad = new SearchRunnable(); } @Override public ObjectAdapter getResultsAdapter() { return mRowsAdapter; } @Override public boolean onQueryTextChange(String newQuery) { mRowsAdapter.clear(); if (!TextUtils.isEmpty(newQuery)) { mDelayedLoad.setSearchQuery(newQuery); mHandler.removeCallbacks(mDelayedLoad); mHandler.postDelayed(mDelayedLoad, SEARCH_DELAY_MS); } return true; } @Override public boolean onQueryTextSubmit(String query) { mRowsAdapter.clear(); if (!TextUtils.isEmpty(query)) { mDelayedLoad.setSearchQuery(query); mHandler.removeCallbacks(mDelayedLoad); mHandler.postDelayed(mDelayedLoad, SEARCH_DELAY_MS); } return true; } }The example code shown above is meant to be used with a separate
SearchRunnable
class
that runs the search query on a separate thread. This technique keeps potentially slow-running queries from blocking the main user interface thread.
相關文章
- Android TV-Building TV Apps,Get Started with TV AppsAndroidUIAPP
- android tv-TV Apps ChecklistAndroidAPP
- Android TV開發——RecyclerView For TVAndroidView
- Android TV-Building Layouts for TVAndroidUI
- android tv-Building TV GamesAndroidUIGAM
- android TV-Building TV Channels,Developing a TV Input ServiceAndroidUIdev
- Android TVAndroid
- Android TV-Handling TV HardwareAndroid
- Android TV-Creating TV NavigationAndroidNavigation
- android TV-Recommending TV Content,Android
- 一起看 I/O | Google TV 和 Android TV OS 的最新進展GoAndroid
- Android TV開發總結【RecycleView】AndroidView
- android TV-Working with Channel DataAndroid
- android tv-Managing User InteractionAndroid
- Java TV MHPJava
- Microsoft opens up Office apps for Android tabletsROSAPPAndroid
- PcMagazine:羅技TV、谷歌TV、Roku XDS三大網際網路TV引數對比谷歌
- stf 怎麼使用在 android tv 上Android
- Android TV版小米盒子專版亮相Android
- Android TV端RecyclerView焦點亂跑AndroidView
- Android Jetpack - Android TV 應用開發教程AndroidJetpack
- 鬥魚TV回應直播造人 鬥魚TV直播造娃娃事件始末事件
- [譯]利用 Android 構建 TV 的未來Android
- [譯] 利用 Android 構建 TV 的未來Android
- [譯]SearchFragment --Android TV 開發手冊十二FragmentAndroid
- 蘋果最新的Apple TV怎麼樣?全新Apple TV解析蘋果APP
- OEM in Apps 11.5.10.2APP
- Why mobile web apps are slowWebAPP
- Create apps with Ribbon UIAPPUI
- 如何阻止Google Apps在Android後臺耗電?GoAPPAndroid
- 【原創】.NET Core應用型別(Portable apps & Self-contained apps)型別APPAI
- 聊聊真實的 Android TV 開發技術棧Android
- Android Auto-Building Apps for Auto,Getting Started with AutoAndroidUIAPP
- [譯] Performance testing of Flutter appsORMFlutterAPP
- Testing Flutter apps翻譯FlutterAPP
- 什麼是 Immutable Web AppsWebAPP
- Apps DBA 談Oracle EBS 安全APPOracle
- Managing Rails Apps at Massive ScaleAIAPP