Example usage for android.app SearchManager INTENT_ACTION_GLOBAL_SEARCH

List of usage examples for android.app SearchManager INTENT_ACTION_GLOBAL_SEARCH

Introduction

In this page you can find the example usage for android.app SearchManager INTENT_ACTION_GLOBAL_SEARCH.

Prototype

String INTENT_ACTION_GLOBAL_SEARCH

To view the source code for android.app SearchManager INTENT_ACTION_GLOBAL_SEARCH.

Click Source Link

Document

Intent action for starting the global search activity.

Usage

From source file:com.farmerbb.taskbar.activity.KeyboardShortcutActivity.java

@SuppressWarnings("deprecation")
@Override/*from   w w w  .  ja va2  s.co m*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Perform different actions depending on how this activity was launched
    switch (getIntent().getAction()) {
    case Intent.ACTION_MAIN:
        Intent selector = getIntent().getSelector();
        Set<String> categories = selector != null ? selector.getCategories() : getIntent().getCategories();

        if (categories.contains(Intent.CATEGORY_APP_MAPS)) {
            SharedPreferences pref = U.getSharedPreferences(this);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && pref.getBoolean("freeform_hack", false)
                    && isInMultiWindowMode() && !FreeformHackHelper.getInstance().isFreeformHackActive()) {
                U.startFreeformHack(this, false, false);
            }

            Intent startStopIntent;

            if (pref.getBoolean("taskbar_active", false))
                startStopIntent = new Intent("com.farmerbb.taskbar.QUIT");
            else
                startStopIntent = new Intent("com.farmerbb.taskbar.START");

            startStopIntent.setPackage(BuildConfig.APPLICATION_ID);
            sendBroadcast(startStopIntent);
        } else if (categories.contains(Intent.CATEGORY_APP_CALENDAR))
            U.lockDevice(this);

        break;
    case Intent.ACTION_ASSIST:
        if (U.isServiceRunning(this, StartMenuService.class)) {
            LocalBroadcastManager.getInstance(this)
                    .sendBroadcast(new Intent("com.farmerbb.taskbar.TOGGLE_START_MENU"));
        } else {
            Intent intent = new Intent("com.google.android.googlequicksearchbox.TEXT_ASSIST");
            if (intent.resolveActivity(getPackageManager()) == null)
                intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);

            if (intent.resolveActivity(getPackageManager()) != null) {
                SharedPreferences pref = U.getSharedPreferences(this);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && pref.getBoolean("freeform_hack", false)
                        && isInMultiWindowMode()) {
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
                    U.launchAppMaximized(getApplicationContext(), intent);
                } else {
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);
                }
            }
        }
        break;
    }

    finish();
}

From source file:com.example.android.actionbarcompat.morf.MainActivity.java

private void openSearch() {
    startActivity(new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH));
}

From source file:com.android.launcher2.Launcher.java

/**
 * Starts the global search activity. This code is a copied from SearchManager
 *///from www  . j  a va 2s .  c  o  m
public void startGlobalSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData,
        Rect sourceBounds) {
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
    if (globalSearchActivity == null) {
        Log.w(TAG, "No global search activity found.");
        return;
    }
    Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setComponent(globalSearchActivity);
    // Make sure that we have a Bundle to put source in
    if (appSearchData == null) {
        appSearchData = new Bundle();
    } else {
        appSearchData = new Bundle(appSearchData);
    }
    // Set source to package name of app that starts global search, if not set already.
    if (!appSearchData.containsKey("source")) {
        appSearchData.putString("source", getPackageName());
    }
    intent.putExtra(SearchManager.APP_DATA, appSearchData);
    if (!TextUtils.isEmpty(initialQuery)) {
        intent.putExtra(SearchManager.QUERY, initialQuery);
    }
    if (selectInitialQuery) {
        intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
    }
    intent.setSourceBounds(sourceBounds);
    try {
        startActivity(intent);
    } catch (ActivityNotFoundException ex) {
        Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
    }
}

From source file:com.android.soma.Launcher.java

/**
 * Starts the global search activity. This code is a copied from SearchManager
 *//*from  ww  w  . j av  a2 s .  c  o m*/
private void startGlobalSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData,
        Rect sourceBounds) {
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
    if (globalSearchActivity == null) {
        Log.w(TAG, "No global search activity found.");
        return;
    }
    Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setComponent(globalSearchActivity);
    // Make sure that we have a Bundle to put source in
    if (appSearchData == null) {
        appSearchData = new Bundle();
    } else {
        appSearchData = new Bundle(appSearchData);
    }
    // Set source to package name of app that starts global search, if not set already.
    if (!appSearchData.containsKey("source")) {
        appSearchData.putString("source", getPackageName());
    }
    intent.putExtra(SearchManager.APP_DATA, appSearchData);
    if (!TextUtils.isEmpty(initialQuery)) {
        intent.putExtra(SearchManager.QUERY, initialQuery);
    }
    if (selectInitialQuery) {
        intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
    }
    intent.setSourceBounds(sourceBounds);
    try {
        startActivity(intent);
    } catch (ActivityNotFoundException ex) {
        Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
    }
}

From source file:com.klinker.android.launcher.launcher3.Launcher.java

/**
 * Starts the global search activity. This code is a copied from SearchManager
 *///from   www .ja  v  a 2 s .  c o  m
private void startGlobalSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData,
        Rect sourceBounds) {
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
    if (globalSearchActivity == null) {
        Log.w(TAG, "No global search activity found.");
        return;
    }
    Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setComponent(globalSearchActivity);
    // Make sure that we have a Bundle to put source in
    if (appSearchData == null) {
        appSearchData = new Bundle();
    } else {
        appSearchData = new Bundle(appSearchData);
    }
    // Set source to package name of app that starts global search if not set already.
    if (!appSearchData.containsKey("source")) {
        appSearchData.putString("source", getPackageName());
    }
    intent.putExtra(SearchManager.APP_DATA, appSearchData);
    if (!TextUtils.isEmpty(initialQuery)) {
        intent.putExtra(SearchManager.QUERY, initialQuery);
    }
    if (selectInitialQuery) {
        intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
    }
    intent.setSourceBounds(sourceBounds);
    try {
        startActivity(intent);
    } catch (ActivityNotFoundException ex) {
        Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
    }
}

From source file:com.android.launcher3.Launcher.java

/**
 * Starts the global search activity. This code is a copied from SearchManager
 *//* w  ww . j  av  a2  s.c om*/
public void startGlobalSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData,
        Rect sourceBounds) {
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
    if (globalSearchActivity == null) {
        Log.w(TAG, "No global search activity found.");
        return;
    }
    Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setComponent(globalSearchActivity);
    // Make sure that we have a Bundle to put source in
    if (appSearchData == null) {
        appSearchData = new Bundle();
    } else {
        appSearchData = new Bundle(appSearchData);
    }
    // Set source to package name of app that starts global search if not set already.
    if (!appSearchData.containsKey("source")) {
        appSearchData.putString("source", getPackageName());
    }
    intent.putExtra(SearchManager.APP_DATA, appSearchData);
    if (!TextUtils.isEmpty(initialQuery)) {
        intent.putExtra(SearchManager.QUERY, initialQuery);
    }
    if (selectInitialQuery) {
        intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
    }
    intent.setSourceBounds(sourceBounds);
    try {
        startActivity(intent);
    } catch (ActivityNotFoundException ex) {
        Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
    }
}