인기 급상승 검색어
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
인기 급상승 검색어 UI 뷰 생성기 요청
검색어 추천 요청과 마찬가지로 인기 급상승 검색어 UI 뷰를 가져오려면 먼저 다음 단계에 따라 생성기를 가져와야 합니다.
- 타겟
Activity
클래스가 GetSearchSuggestionsViewGeneratorCallback
인터페이스를 구현하거나 익명의 내부 클래스를 사용하도록 합니다.
GetSearchSuggestionsViewGeneratorCallback
인터페이스의 onSuccess(SearchSuggestionsViewGenerator)
및 onError(String)
메서드를 재정의합니다.
- 지정된 최대 인기 급상승 검색어 수로
GetTrendingSearchesViewOptions
클래스 인스턴스를 만듭니다. (선택사항) 이 객체는 검색 추천 UI의 모양을 맞춤설정하는 몇 가지 옵션을 제공하는 SearchSuggestionsViewOptions
객체도 사용합니다.
SearchInAppsService
의 getTrendingSearchesView(GetTrendingSearchesViewOptions,
GetSearchSuggestionsViewGeneratorCallback)
함수를 호출합니다.
- UI 생성기를 가져온 후에는 ViewModel에 저장하여 활동을 다시 만들어야 할 때 (예: 앱이 실행되는 동안 구성이 변경된 경우) 생성기를 다시 요청하지 않아도 되도록 할 수 있습니다.
샘플 코드
자바
package ...;
...
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.libraries.searchinapps.GetSearchSuggestionsViewGeneratorCallback;
import com.google.android.libraries.searchinapps.GetTrendingSearchesViewOptions;
import com.google.android.libraries.searchinapps.SearchInAppsService;
import com.google.android.libraries.searchinapps.SearchSuggestionsViewGenerator;
...
public class MainActivity extends AppCompatActivity implements GetSearchSuggestionsViewGeneratorCallback {
private SearchInAppsService service;
@Override
public void onSuccess(SearchSuggestionsViewGenerator generator) {
...
}
@Override
public void onError(String errorMessage) {
...
}
@Override
protected void onCreate(Bundle savedInstanceState) {
...
service = SearchInAppsService.create(this);
// Uses the default SearchSuggestionsViewOptions.
service.getTrendingSearchesView(
new GetTrendingSearchesViewOptions().setMaxNumTrends(3), this);
...
}
@Override
public void onDestroy() {
service.shutDown();
super.onDestroy();
}
}
Jetpack Compose
package ...
...
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.platform.LocalContext
import com.google.android.libraries.searchinapps.GetSearchSuggestionsViewGeneratorCallback
import com.google.android.libraries.searchinapps.GetSearchSuggestionsViewOptions
import com.google.android.libraries.searchinapps.SearchInAppsService
import com.google.android.libraries.searchinapps.SearchSuggestionsViewGenerator
...
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
SearchSuggestionsUI()
}
}
@Composable
fun SearchSuggestionsUI() {
...
var service by remember {
mutableStateOf<SearchInAppsService?>(
SearchInAppsService.create(LocalContext.current))
}
DisposableEffect(Unit) { onDispose { service?.shutDown() } }
val callback =
object : GetSearchSuggestionsViewGeneratorCallback {
override fun onSuccess(generator: SearchSuggestionsViewGenerator) {
...
}
override fun onError(errorMessage: String) {
...
}
}
// Uses the default SearchSuggestionsViewOptions.
var options: GetTrendingSearchesViewOptions =
GetTrendingSearchesViewOptions()
.setMaxNumTrends(3)
service?.getTrendingSearchesView(options, callback)
...
}
}
인기 급상승 검색어 UI 뷰 추가
인기 급상승 검색어 UI 뷰를 앱 UI에 추가하는 방법은 검색 추천 기능과 동일합니다.
다음: 검색 결과 표시arrow_forward
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-25(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-25(UTC)"],[[["\u003cp\u003eTo display trending searches in your Android app, you need to obtain a UI view generator from the \u003ccode\u003eSearchInAppsService\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eImplement the \u003ccode\u003eGetSearchSuggestionsViewGeneratorCallback\u003c/code\u003e interface in your Activity to handle the success or failure of the generator retrieval.\u003c/p\u003e\n"],["\u003cp\u003eCustomize the number of trending searches displayed and the UI appearance using \u003ccode\u003eGetTrendingSearchesViewOptions\u003c/code\u003e and \u003ccode\u003eSearchSuggestionsViewOptions\u003c/code\u003e respectively.\u003c/p\u003e\n"],["\u003cp\u003eUtilize the obtained generator to seamlessly integrate the trending searches UI into your app's layout, similar to adding search suggestions.\u003c/p\u003e\n"],["\u003cp\u003eStore the generator in a ViewModel to avoid redundant requests when the activity is recreated.\u003c/p\u003e\n"]]],["To implement trending searches, first, have your `Activity` implement `GetSearchSuggestionsViewGeneratorCallback`. Override `onSuccess` and `onError` methods. Optionally, create a `GetTrendingSearchesViewOptions` instance to customize settings like the maximum number of trends. Call `SearchInAppsService`'s `getTrendingSearchesView`, passing the options and callback. Store the retrieved `SearchSuggestionsViewGenerator` in a ViewModel to avoid repeated requests. Adding the generated view into your app's UI is done similarly to search suggestions.\n"],null,["# Trending searches\n\nRequest trending searches UI view generator\n-------------------------------------------\n\nSimilar to request search suggestions, to get the trending searches UI view, you\nshould get its generator first by the following steps:\n\n1. Let your target `Activity` class implement the `GetSearchSuggestionsViewGeneratorCallback` interface or use the anonymous inner class.\n2. Override the `GetSearchSuggestionsViewGeneratorCallback` interface's `onSuccess(SearchSuggestionsViewGenerator)` and `onError(String)` methods.\n3. Construct the `GetTrendingSearchesViewOptions` class instance with the maximum number of trending searches specified. (Optional) This object also takes a `SearchSuggestionsViewOptions` object which provides some options to customize the appearance of the search suggestions UI.\n4. Call `SearchInAppsService`'s `getTrendingSearchesView(GetTrendingSearchesViewOptions,\n GetSearchSuggestionsViewGeneratorCallback)` function.\n5. After you get the UI generator, you can consider storing it in a ViewModel so that you don't need to ask for the generator again when the activity needs to to be recreated (like when the configuration has changed while the app is running).\n\nSample code \n\n### Java\n\n package ...;\n\n ...\n import androidx.appcompat.app.AppCompatActivity;\n import com.google.android.libraries.searchinapps.GetSearchSuggestionsViewGeneratorCallback;\n import com.google.android.libraries.searchinapps.GetTrendingSearchesViewOptions;\n import com.google.android.libraries.searchinapps.SearchInAppsService;\n import com.google.android.libraries.searchinapps.SearchSuggestionsViewGenerator;\n ...\n\n public class MainActivity extends AppCompatActivity implements GetSearchSuggestionsViewGeneratorCallback {\n private SearchInAppsService service;\n\n @Override\n public void onSuccess(SearchSuggestionsViewGenerator generator) {\n ...\n }\n\n @Override\n public void onError(String errorMessage) {\n ...\n }\n\n @Override\n protected void onCreate(Bundle savedInstanceState) {\n ...\n service = SearchInAppsService.create(this);\n // Uses the default SearchSuggestionsViewOptions.\n service.getTrendingSearchesView(\n new GetTrendingSearchesViewOptions().setMaxNumTrends(3), this);\n ...\n }\n\n @Override\n public void onDestroy() {\n service.shutDown();\n super.onDestroy();\n }\n }\n\n### Jetpack Compose\n\n package ...\n\n ...\n import android.os.Bundle\n import androidx.activity.compose.setContent\n import androidx.appcompat.app.AppCompatActivity\n import androidx.compose.runtime.Composable\n import androidx.compose.runtime.DisposableEffect\n import androidx.compose.runtime.mutableStateOf\n import androidx.compose.ui.platform.LocalContext\n import com.google.android.libraries.searchinapps.GetSearchSuggestionsViewGeneratorCallback\n import com.google.android.libraries.searchinapps.GetSearchSuggestionsViewOptions\n import com.google.android.libraries.searchinapps.SearchInAppsService\n import com.google.android.libraries.searchinapps.SearchSuggestionsViewGenerator\n ...\n\n class MainActivity : AppCompatActivity() {\n override fun onCreate(savedInstanceState: Bundle?) {\n super.onCreate(savedInstanceState)\n setContent {\n SearchSuggestionsUI()\n }\n }\n\n @Composable\n fun SearchSuggestionsUI() {\n ...\n var service by remember {\n mutableStateOf\u003cSearchInAppsService?\u003e(\n SearchInAppsService.create(LocalContext.current))\n }\n DisposableEffect(Unit) { onDispose { service?.shutDown() } }\n val callback =\n object : GetSearchSuggestionsViewGeneratorCallback {\n override fun onSuccess(generator: SearchSuggestionsViewGenerator) {\n ...\n }\n\n override fun onError(errorMessage: String) {\n ...\n }\n }\n // Uses the default SearchSuggestionsViewOptions.\n var options: GetTrendingSearchesViewOptions =\n GetTrendingSearchesViewOptions()\n .setMaxNumTrends(3)\n service?.getTrendingSearchesView(options, callback)\n ...\n }\n }\n\nAdd trending searches UI view\n-----------------------------\n\nThe way to add trending searches UI view into your app UI is the same as the\n[search suggestions](/search-in-apps/android/search_suggestions#add_search_suggestions_ui_view)\nfeature.\n\n[Next: Display search resultsarrow_forward](/search-in-apps/android/display_search_results)"]]