Android How to - Intent Web Search with keyword








The following code shows how to do Intent Web Search with keyword.

Example

Main Activity Java code

/*  w w w . ja  v  a2s  .  c om*/
import java.io.File;
import java.util.ArrayList;

import android.app.Activity;
import android.app.SearchManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.Contacts;
import android.view.Menu;

public class MainActivity extends Activity {

    private Intent browserIntent;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        browserIntent = new Intent();
        //browserIntent.setAction(Intent.ACTION_VIEW);
        //browserIntent.setData(Uri.parse("http://www.google.com"));
        browserIntent.setAction(Intent.ACTION_WEB_SEARCH);
        browserIntent.putExtra(SearchManager.QUERY, "puppies");
        
        
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add("Browser").setIntent(browserIntent);
        return true;
    }

}
null