কম্পিউটার টিউটোরিয়াল

অ্যান্ড্রয়েড অ্যাপে গুগল সার্চ ফাংশনালিটি যোগ করা

ইন্টেন্ট ব্যবহার করে গুগল সার্চ ইন্টিগ্রেশন

এই টিউটোরিয়ালটি দেখাবে কীভাবে.ACTION_WEB_SEARCH ইন্টেন্ট ব্যবহার করে আপনার অ্যাপ থেকে সরাসরি গুগল সার্চ চালু করা যায়।

পদক্ষেপ ১: প্রজেক্ট তৈরি করুন

Android Studio-তে নতুন প্রজেক্ট শুরু করুন।

পদক্ষেপ ২: লেআউট XML (activity_main.xml)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
    xmlns:tools="https://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center"
    tools:context=".MainActivity">

    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:hint="Search query..." />

    <Button
        android:id="@+id/btnSearch"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Search" />

</LinearLayout>

পদক্ষেপ ৩: MainActivity.java

import androidx.appcompat.app.AppCompatActivity;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {
    EditText editText;
    Button btnSearch;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        editText = findViewById(R.id.editText);
        btnSearch = findViewById(R.id.btnSearch);

        btnSearch.setOnClickListener(v -> {
            String query = editText.getText().toString().trim();
            if (!query.isEmpty()) {
                Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
                intent.putExtra(SearchManager.QUERY, query);
                
                // ভয়েস সার্চের জন্য বিকল্প
                // intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
                
                if (intent.resolveActivity(getPackageManager()) != null) {
                    startActivity(intent);
                } else {
                    // ফলব্যাক: ব্রাউজার খুলুন
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, 
                        Uri.parse("https://www.google.com/search?q=" + Uri.encode(query)));
                    startActivity(browserIntent);
                }
            }
        });
    }
}

পদক্ষেপ ৪: AndroidManifest.xml - ইন্টারনেট পারমিশন

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

গুরুত্বপূর্ণ পয়েন্টসমূহ

  • ACTION_WEB_SEARCH: সিস্টেমের ডিফল্ট সার্চ অ্যাপ (সাধারণত গুগল) খোলে
  • SearchManager.QUERY: সার্চ কোয়েরি পাস করার স্ট্যান্ডার্ড কী
  • resolveActivity: সার্চ অ্যাপ ইনস্টল না থাকলে ক্র্যাশ প্রতিরোধ
  • ফলব্যাক: ব্রাউজার ইন্টেন্ট ব্যবহার করুন বিকল্প হিসেবে

উন্নত সার্চ ফিচার

// নির্দিষ্ট সাইটে সার্চ
intent.putExtra(SearchManager.QUERY, "site:github.com android tutorial");

// ভয়েস সার্চ লঞ্চ
Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
startActivityForResult(voiceIntent, REQUEST_CODE);

সেরা অনুশীলন

  • ইনপুট যাচাই করুন (খালি কোয়েরি প্রতিরোধ)
  • সার্চ ইতিহাস সংরক্ষণ করুন (SharedPreferences/Room)
  • সাজেশন/অটোকমপ্লিট যোগ করুন
  1. অ্যান্ড্রয়েড অ্যাপে ক্যালেন্ডার ইভেন্ট যোগ করার পদ্ধতি

  2. Android Studio-এ JAR ফাইল লাইব্রেরি হিসেবে যোগ করার পদ্ধতি

  3. Google Search-এ আপনার Google People Card যোগ করুন

  4. এন্ড্রয়েডে গুগল অ্যাপ কাজ করছে না সমস্যা সমাধান: ধাপে ধাপে ট্রাবলশুটিং গাইড