Search code examples
androidbrowsergoogle-search

Google Search Engine in AddressBar of Android Application


Is possible to use the "Google" Search Engine, with tips in my Browser Application in Android? I'm developing a browser, that search for contents in an EditText (used as addressbar), but only by an URL instead of a word. Is possible to make this, detecting when user is searching for an url? Thanks in advance.


Solution

  • Solved by coding this:

    public static final String SEARCH_ENGINE_GOOGLE = "https://www.google.com/search?q=";

        mUrlView.setOnEditorActionListener(new EditText.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_DONE) {
                    //   submit_btn.performClick();
    
                    if (mUrlView.getText().toString().contains("http://")) {
                        mWebView.loadUrl(mUrlView.getText().toString());
                    } else if (mUrlView.getText().toString().contains(".")) {
    
    
                        mWebView.loadUrl("http://" + mUrlView.getText().toString());
    
    
                    } else {
                        mWebView.loadUrl(SEARCH_ENGINE_GOOGLE + mUrlView.getText().toString());
    
                    }
    
                    return true;
    
    
                } else {
                    mWebView.loadUrl(mUrlView.getText().toString());
    
                    return false;
                }
            }
        });
    
    
        return v;
    
    
    }
    

    By adding the Google search prefix if the text in the TextBox doesn't contains any dot or http://