user2223317
user2223317

Reputation: 211

Search any web with keyword in Android

I developed an app..that will search for keywords that the user entered in the edittext...the app is working fine..but now the app only searches in Google..I need to search the keyword the user is giving..it should search in a site..for ex: http://www.java2s.com/Open-Source/Android/android-platform-apps/Browser/com/android/browser/search/DefaultSearchEngine.java.htm .. for this what cchange I have to do..I am giving the code below..pls help...`

btn.setOnClickListener(new View.OnClickListener()   
    {

        @Override
        public void onClick(View v)

        {
            // TODO Auto-generated method stub
             Editable searchText = ev.getText();
            Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
            intent.putExtra(SearchManager.QUERY, ev.getText().toString());                                                                                           
            startActivity(intent); 


        }
    });         `

Upvotes: 0

Views: 2353

Answers (3)

Faizan Haidar Khan
Faizan Haidar Khan

Reputation: 1215

Any keyword can be searched using same intent, but by adding a query with the static url. Like this

 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.com/search?q=" + string));
 startActivity(intent);

Upvotes: 2

user2134354
user2134354

Reputation:

@ user2223317.. Instead of using ACTION_WEB_SEARCH try to use ..ACTION_VIEW ...it will works... try to do the following code

`@Override
        public void onClick(View v)

        {
            // TODO Auto-generated method stub
             Editable searchText = ev.getText();
            Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://stackoverflow.com/"));
            intent.putExtra(SearchManager.QUERY, ev.getText().toString()); 

            startActivity(intent); `

and dnt forget to accept my answer..if it works...thanks...

Upvotes: 3

Akhil
Akhil

Reputation: 6697

In that case you need to write your own SearchManager. You can write one using one WebView which will take two paramas "SITE_TO_BE_SEARCH" and "QUERY".. Now all searches will be performed within your app, no need to launching external Browser App. Look for any WebView sample app, you will find many.

Upvotes: 1

Related Questions