Over a million developers have joined DZone.

Android – How to Implement Google Search Inside Your App

· Java Zone

Learn more about the advantages of moving from a monolithic to microservices architecture.  Brought to you in partnership with IBM.

Here is an easy solution to implement Google Searching in your Android App. In this example, we will accept input from the user and will search the same string input in a Google search. To implement this functionality we use Intent.ACTION_WEB_SEARCH .

Now for some code...

package com.technotalkative.googlesearchintent;

import android.app.Activity;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class GoogleSearchIntentActivity extends Activity {

	private EditText editTextInput;

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

        editTextInput = (EditText) findViewById(R.id.editTextInput);

    public void onSearchClick(View v)
    	try {
    		 Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
             String term = editTextInput.getText().toString();
             intent.putExtra(SearchManager.QUERY, term);
		} catch (Exception e) {
			// TODO: handle exception



<!--?xml version="1.0" encoding="utf-8"?-->
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:padding="10dp">

    <edittext android:id="@+id/editTextInput" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Enter search text">


    <button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Search" android:layout_gravity="center" android:onclick="onSearchClick" android:layout_margintop="10dp">



Don’t forget to add INTERNET permission inside the AndroidManifest.xml file.

 <uses-permission android:name="android.permission.INTERNET">

Android - Google search intent
Android - Google search intent

Download full source code of this example: Android – Implementation of Google Search Intent



From Idea to Application gives you the architecture to quickly build, manage and run a range of applications (web, mobile, big data, new smart devices, etc.) on an open-standard, cloud-based platform. See why developers are using IBM Bluemix. Brought to you in partnership with IBM.


Published at DZone with permission of Paresh Mayani. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}