Android में डायलर खोलने का पूरा गाइड
यह उदाहरण दर्शाता है कि Android ऐप में किसी फोन नंबर के साथ डायलर कैसे खोला जाता है। यह एक सामान्य आवश्यकता है जब आप उपयोगकर्ता को सीधे कॉल करने की सुविधा देना चाहते हैं।
चरण 1: नया प्रोजेक्ट बनाएं
Android Studio में जाएं, File → New Project चुनें और सभी आवश्यक विवरण भरकर एक नया प्रोजेक्ट बनाएं।
चरण 2: लेआउट फ़ाइल में कोड जोड़ें (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"
android:padding="8dp"
tools:context=".MainActivity">
<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" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="phone"
android:linksClickable="true" />
</RelativeLayout>
चरण 3: MainActivity.java में कोड जोड़ें
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void ShowDialer(View view) {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:0123456789"));
startActivity(intent);
}
}
चरण 4: AndroidManifest.xml में अनुमति जोड़ें
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
package="app.com.sample">
<uses-permission android:name="android.permission.CALL_PHONE" />
<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>
ऐप चलाएं और टेस्ट करें
अपने Android डिवाइस को कंप्यूटर से कनेक्ट करें। Android Studio में टूलबार से Run आइकन पर क्लिक करें। अपना डिवाइस चुनें और देखें कि बटन दबाने पर डायलर निर्दिष्ट नंबर के साथ खुलता है।