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

কোটলিন ব্যবহার করে অ্যান্ড্রয়েডে ফোন নম্বরসহ ডায়েলার খোলা

ওভারভিউ

এই উদাহরণটি দেখায় কিভাবে কোটলিনে Intent.ACTION_DIAL ব্যবহার করে ডিফল্ট ফোন ডায়েলার খোলা যায় এবং একটি নির্দিষ্ট ফোন নম্বর প্রি-ফিল (Pre-fill) করা যায়। ব্যবহারকারী কল বাটন চাপলে কল শুরু হবে।

পূর্বশর্ত

  • অ্যান্ড্রয়েড স্টুডিও (কোটলিন)
  • CALL_PHONE পারমিশন দরকার নেই (শুধু ডায়েলার খুললেই যথেষ্ট)

ধাপ ১: প্রজেক্ট তৈরি করুন

File → New Project → Empty Activity → Language: Kotlin।

ধাপ ২: লেআউট (res/layout/activity_main.xml)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="50dp"
        android:text="Tutorials Point"
        android:textAlignment="center"
        android:textColor="@android:color/holo_green_dark"
        android:textSize="32sp"
        android:textStyle="bold" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginTop="40dp"
        android:onClick="showDialer"
        android:text="Show Number Dialer" />

</RelativeLayout>

ধাপ ৩: MainActivity.kt

package com.example.opendialer

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        title = "KotlinApp"
    }

    fun showDialer(view: View) {
        val intent = Intent(Intent.ACTION_DIAL)
        intent.data = Uri.parse("tel:0123456789") // এখানে আপনার ফোন নম্বর দিন
        startActivity(intent)
    }
}

ধাপ ৪: AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
    package="com.example.opendialer">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>

চলান ও ফলাফল

  1. অ্যাপ চালান এবং "Show Number Dialer" বাটনে ট্যাপ করুন।
  2. ডিফল্ট ফোন ডায়েলার খুলবে যেখানে নম্বর 0123456789 প্রি-ফিল থাকবে।
  3. ব্যবহারকারী কল আইকনে ট্যাপ করলে কল শুরু হবে।

মূল পার্থক্য: ACTION_DIAL vs ACTION_CALL

ইন্টেন্টব্যবহারপারমিশন
Intent.ACTION_DIALডায়েলার খোলে, ব্যবহারকারী কল শুরু করেদরকার নেই
Intent.ACTION_CALLসরাসরি কল শুরু করে (ব্যবহারকারী ইন্টারঅ্যাকশন ছাড়া)CALL_PHONE (Dangerous)

সুরক্ষা: সবসময় ACTION_DIAL ব্যবহার করুন। ACTION_CALL শুধু বিশেষ পরিস্থিতিতে (যেমন: ইমার্জেন্সি অ্যাপ) এবং ব্যবহারকারীর স্পষ্ট সম্মতিতে ব্যবহার করুন।

অতিরিক্ত ফিচার

  • USSD কোড: Uri.parse("tel:*123%23") ( *123# )
  • ভয়েসমেইল: Uri.parse("voicemail:123456789")
  • SMS খোলা: Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:0123456789"))

নম্বর ফরম্যাটিং

আন্তর্জাতিক ফরম্যাটে: tel:+8801XXXXXXXXX (বাংলাদেশের জন্য +880)। স্পেস বা ড্যাশ ইগনোর করা হয়।

  1. অ্যান্ড্রয়েডে কন্টেন্ট প্রোভাইডার থেকে ফোন নম্বর পাওয়ার পদ্ধতি

  2. Android-এ Intent ব্যবহার করে ফোন কল করার পদ্ধতি

  3. অ্যান্ড্রয়েড অ্যাপের বিল্ড ভার্সন নাম্বার কীভাবে পেতে হয়?

  4. অ্যান্ড্রয়েডে প্রোগ্রাম্যাটিক্যালি ফোন নম্বর পাওয়ার পদ্ধতি