gpt4 book ai didi

android - 打开全局搜索作为覆盖

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:59:14 26 4
gpt4 key购买 nike

我正在编写一个启动器,希望能够在 Google 应用程序中以叠加层而不是全屏方式打开搜索。

目前我只找到一种在Google App全屏打开搜索的方法如下(摘自AOSP Launcher3源码):

 public static boolean openSearch(Context context) {

SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
if (globalSearchActivity == null) {
Timber.w("No global search activity found.");
return false;
}
Intent intent = new Intent(android.app.SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(globalSearchActivity);
Bundle appSearchData = new Bundle();
appSearchData.putString("source", "launcher-search");

intent.putExtra(android.app.SearchManager.APP_DATA, appSearchData);

intent.putExtra(android.app.SearchManager.QUERY, "");
intent.putExtra(android.app.SearchManager.EXTRA_SELECT_QUERY, true);
try {
context.startActivity(intent);
return true;
} catch (ActivityNotFoundException ex) {
Timber.w("Global search activity not found: %s", globalSearchActivity);
return false;
}

}

我知道这是可能的,因为 Nova 和 Action Launcher 等其他启动器设法做到了......

最佳答案

想通了...

public static boolean showGlobalSearchOverlay(Context context) {
ComponentName globalSearchActivity =
new ComponentName("com.google.android.googlequicksearchbox",
"com.google.android.apps.gsa.queryentry.QueryEntryActivity");

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(globalSearchActivity);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

try {
context.startActivity(intent);
return true;
} catch (Throwable e) {
Timber.w("Unable to show search overlay");
return false;
}
}

关于android - 打开全局搜索作为覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38213445/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com