Android SearchManager - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android SearchManager class.

This code example shows how to use the following methods:startSearch, stopSearch
        SearchManager searchManager = (SearchManager)
                mContext.getSystemService(Context.SEARCH_SERVICE);
        assertNotNull(searchManager);
 
        // These tests should simply run to completion w/o exceptions 
        searchManager.startSearch(null, false, SEARCHABLE_ACTIVITY, null, false);
        searchManager.stopSearch();
 
        searchManager.startSearch("", false, SEARCHABLE_ACTIVITY, null, false);
        searchManager.stopSearch();
 
        searchManager.startSearch("test search string", false, SEARCHABLE_ACTIVITY, null, false);
        searchManager.stopSearch();
 
        searchManager.startSearch("test search string", true, SEARCHABLE_ACTIVITY, null, false);
        searchManager.stopSearch();
    } 
 
} 
7
CodeRank
This code example shows how to use the following methods:getSearchableInfo, getWebSearchActivity
    } 
 
    public static DefaultSearchEngine create(Context context) {
        SearchManager searchManager =
                (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
        ComponentName name = searchManager.getWebSearchActivity();
        if (name == null) return null;
        SearchableInfo searchable = searchManager.getSearchableInfo(name);
        if (searchable == null) return null;
        return new DefaultSearchEngine(context, searchable);
    } 
 
    private CharSequence loadLabel(Context context, ComponentName activityName) {
        PackageManager pm = context.getPackageManager();
        try { 
            ActivityInfo ai = pm.getActivityInfo(activityName, 0);
            return ai.loadLabel(pm);
        } catch (PackageManager.NameNotFoundException ex) {
            Log.e(TAG, "Web search activity not found: " + activityName);
            return null; 
7
CodeRank
This code example shows how to use the following methods:getSearchablesInGlobalSearch
 
    protected void addInternalSources() { 
    } 
 
    private void addSearchableSources() { 
        List<SearchableInfo> searchables = mSearchManager.getSearchablesInGlobalSearch();
        if (searchables == null) {
            Log.e(TAG, "getSearchablesInGlobalSearch() returned null");
            return; 
        } 
        for (SearchableInfo searchable : searchables) {
            SearchableSource source = createSearchableSource(searchable);
            if (source != null) {
                if (DBG) Log.d(TAG, "Created source " + source);
                addSource(source);
            } 
        } 
    } 
 
    protected void addSource(Source source) {
6
CodeRank
This code example shows how to use the following methods:getSearchableInfo, getWebSearchActivity
    } 
 
    public static DefaultSearchEngine create(Context context) {
        SearchManager searchManager =
                (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
        ComponentName name = searchManager.getWebSearchActivity();
        if (name == null) return null;
        SearchableInfo searchable = searchManager.getSearchableInfo(name);
        if (searchable == null) return null;
        return new DefaultSearchEngine(context, searchable);
    } 
 
    private CharSequence loadLabel(Context context, ComponentName activityName) {
        PackageManager pm = context.getPackageManager();
        try { 
            ActivityInfo ai = pm.getActivityInfo(activityName, 0);
            return ai.loadLabel(pm);
        } catch (PackageManager.NameNotFoundException ex) {
            Log.e(TAG, "Web search activity not found: " + activityName);
            return null; 
4
CodeRank
This code example shows how to use the following methods:getSearchableInfo
        private String mQuery;
        private Handler mHandler = new Handler(Looper.getMainLooper());
 
        public LiveSourceCheck(String src, ComponentName componentName, String query) {
            mSrc = src;
            mSearchable = mSearchManager.getSearchableInfo(componentName);
            assert(mSearchable != null);
            assert(mSearchable.getSuggestAuthority() != null);
            mQuery = query;
        } 
 
        public void run() { 
            Cursor cursor = null;
            try { 
                final long start = System.nanoTime();
                cursor = getSuggestions(mSearchable, mQuery);
                long end = System.nanoTime();
                long elapsed = (end - start);
                if (cursor == null) {
                    Log.d(TAG, mSrc + ": null cursor in " + formatTime(elapsed)
4
CodeRank
This code example shows how to use the following methods:getSearchableInfo, getWebSearchActivity
    } 
 
    public static DefaultSearchEngine create(Context context) {
        SearchManager searchManager =
                (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
        ComponentName name = searchManager.getWebSearchActivity();
        if (name == null) return null;
        SearchableInfo searchable = searchManager.getSearchableInfo(name);
        if (searchable == null) return null;
        return new DefaultSearchEngine(context, searchable);
    } 
 
    private CharSequence loadLabel(Context context, ComponentName activityName) {
        PackageManager pm = context.getPackageManager();
        try { 
            ActivityInfo ai = pm.getActivityInfo(activityName, 0);
            return ai.loadLabel(pm);
        } catch (PackageManager.NameNotFoundException ex) {
            Log.e(TAG, "Web search activity not found: " + activityName);
            return null; 
4
CodeRank
This code example shows how to use the following methods:getSearchableInfo
 
        // TODO: call finish() when all tasks are done 
    } 
 
    private SearchableInfo getSearchable(ComponentName componentName) {
        SearchableInfo searchable = mSearchManager.getSearchableInfo(componentName);
        if (searchable == null || searchable.getSuggestAuthority() == null) {
            throw new RuntimeException("Component is not searchable: "
                    + componentName.flattenToShortString());
        } 
        return searchable;
    } 
 
    /** 
     * Keeps track of timings in nanoseconds. 
     */ 
    private static class ElapsedTime { 
        private long mTotal = 0;
        private int mCount = 0;
        public synchronized void addTime(long time) {
4
CodeRank
This code example shows how to use the following methods:getSearchableInfo
     
    public static MyDefaultSearchEngine getInstance(Context context) {
        SearchManager searchManager =
                (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
//        ComponentName name = searchManager.getWebSearchActivity(); 
        ComponentName name = (ComponentName) MyInvokeSearchManagerMethod.getWebSearchActivity(searchManager);
 
        if (name == null) return null;
        SearchableInfo searchable = searchManager.getSearchableInfo(name);
        if (searchable == null) return null;
        return new MyDefaultSearchEngine(context, searchable);
    } 
     
    private CharSequence loadLabel(Context context, ComponentName activityName) {
        PackageManager pm = context.getPackageManager();
        try { 
            ActivityInfo ai = pm.getActivityInfo(activityName, 0);
            return ai.loadLabel(pm);
        } catch (PackageManager.NameNotFoundException ex) {
            Log.e(TAG, "Web search activity not found: " + activityName);
4
CodeRank
This code example shows how to use the following methods:getSearchableInfo
	@TargetApi(8) 
	public void addSearchToActionBar(ActionBar actionBar) {
		if (!shouldShowInMenu()) { 
			// Set up a SearchView 
			SearchView searchView = new SearchView(context);
			searchView.setSearchableInfo(searchManager.getSearchableInfo(context.getComponentName()));
			searchView.setQueryRefinementEnabled(true);
			searchView.setIconifiedByDefault(false);
			searchView.setFocusable(false);
			searchView.setFocusableInTouchMode(false);
			actionBar.setCustomView(searchView);
			actionBar.setDisplayShowCustomEnabled(true);
		} 
	} 
 
	@TargetApi(8) 
	public void enhanceSearchInMenu(Menu menu) {
		// For phones, the dashboard & search fragments show a search icon in the action bar 
		// Note that tablets always show an search input in the action bar through the HomeTablet activity directly 
		MenuItem item = menu.findItem(R.id.menu_search);
4
CodeRank
This code example shows how to use the following methods:getSearchableInfo
        private String mQuery;
        private Handler mHandler = new Handler(Looper.getMainLooper());
 
        public LiveSourceCheck(String src, ComponentName componentName, String query) {
            mSrc = src;
            mSearchable = mSearchManager.getSearchableInfo(componentName, false);
            assert(mSearchable != null);
            assert(mSearchable.getSuggestAuthority() != null);
            mQuery = query;
        } 
 
        public void run() { 
            Cursor cursor = null;
            try { 
                final long start = System.nanoTime();
                cursor = mSearchManager.getSuggestions(mSearchable, mQuery);
                long end = System.nanoTime();
                long elapsed = (end - start);
                if (cursor == null) {
                    Log.d(TAG, mSrc + ": null cursor in " + formatTime(elapsed)
4
CodeRank

Related Android SearchManager Questions & Answers:

Other Android SearchManager Examples

4:	
5:			// Associate searchable configuration with the SearchView
6:			SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
7:			SearchView searchView = (SearchView) menu.findItem(R.id.action_search)
8:					.getActionView();
-
4:	
5:			// Associate searchable configuration with the SearchView
6:			SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
7:			SearchView searchView = (SearchView) menu.findItem(R.id.action_search)
8:					.getActionView();

Read More

See Code Examples for Android SearchManager Methods: