Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open global search as overlay

I am writing a launcher and want to be able to open up a search as an overlay rather than full-screen in the Google App.

So far I only found a way to open the search in the Google App full-screen as follows (taken from AOSP Launcher3 source code):

 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;
        }

    }

I know it is possible because other launchers like Nova and Action Launcher managed to do it...

like image 782
timothyjc Avatar asked Jul 05 '16 21:07

timothyjc


People also ask

What is global search on Android?

Android TV provides powerful, built-in search to navigate each app's content. When a user starts a search, the search UI overlays the screen. Global Search. Search is presented as an overlay on the home screen. Users access it by navigating to the Home screen, then pressing the microphone button.

What is global search?

What is Global Search? The Global Search feature is a Google-like search engine within your environment that provides dynamic, object-specific, or cross-object results. This means searches can be executed on a single area as well as multiple areas across the entire system.


1 Answers

Figured it out...

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;
    }
}
like image 95
timothyjc Avatar answered Oct 03 '22 18:10

timothyjc