"CallHub: One-Click Calling Solution"

CallHub: One-Click Calling Solution

যদি আপনি UI এবং Java দিয়ে কাজ করছেন এবং "কল বাটন" ক্লিক করলে সরাসরি কল করতে চান, তাহলে Android অ্যাপে এটি করা সম্ভব। আপনি একটি Intent ব্যবহার করে ডায়াল বা সরাসরি কল করতে পারেন। নিচে একটি উদাহরণ দেওয়া হলো:

কোড উদাহরণ:

Java

 import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;


public class MainActivity extends AppCompatActivity {


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);


        Button callButton = findViewById(R.id.callButton);


        callButton.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {

                // Replace "123456789" with the phone number you want to call

                String phoneNumber = "123456789";

                Intent callIntent = new Intent(Intent.ACTION_CALL);

                callIntent.setData(Uri.parse("tel:" + phoneNumber));


                // Check for CALL_PHONE permission

                if (checkSelfPermission(android.Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED) {

                    startActivity(callIntent);

                } else {

                    // Request permission if not already granted

                    requestPermissions(new String[]{android.Manifest.permission.CALL_PHONE}, 1);

                }

            }

        });

    }

}

Activity_main.xml

XML

<LinearLayout

    xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical"

    android:gravity="center">


    <Button

        android:id="@+id/callButton"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="Call Now" />

</LinearLayout>

Activity_main.xml

XML

<LinearLayout

    xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical"

    android:gravity="center">


    <Button

        android:id="@+id/callButton"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="Call Now" />

</LinearLayout>

গুরুত্বপূর্ণ বিষয়:

1. Permission: সরাসরি কল করতে আপনাকে CALL_PHONE permission যুক্ত করতে হবে AndroidManifest.xml ফাইলে:

Java

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

2. Runtime Permission: Android 6.0 (API Level 23) বা তার উপরে আপনাকে runtime permission চেক করতে হবে, যা উপরের কোডে অন্তর্ভুক্ত আছে।

3.Safety: সরাসরি কলের পরিবর্তে আপনি ডায়ালার ওপেন করতে পারেন (যাতে ব্যবহারকারী নিশ্চিত করতে পারে):

Java

 Intent dialIntent = new Intent(Intent.ACTION_DIAL);

dialIntent.setData(Uri.parse("tel:" + phoneNumber));

startActivity(dialIntent);

Open Chat

buy source code ZIP file

Comments