यह उदाहरण दर्शाता है कि Kotlin का उपयोग करके Android में प्री-फिल्ड फोन नंबर के साथ डायलर ऐप कैसे खोला जाता है। Intent.ACTION_DIAL का उपयोग किया जाता है जो केवल डायलर खोलता है, कॉल नहीं करता।
चरण 1: नया प्रोजेक्ट बनाएं
Android Studio खोलें, File → New Project पर जाएं और नया प्रोजेक्ट बनाने के लिए सभी आवश्यक विवरण भरें।
चरण 2: activity_main.xml में UI जोड़ें
<?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>
चरण 3: MainActivity.kt में डायलर इंटेंट लॉन्च करें
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)
}
}
चरण 4: AndroidManifest.xml कॉन्फ़िगर करें
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
package="com.example.q11">
<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 आइकन पर क्लिक करें। अपना मोबाइल डिवाइस चुनें और ऐप चलने पर डिफ़ॉल्ट स्क्रीन देखें।
महत्वपूर्ण अंतर:
| इंटेंट एक्शन | व्यवहार | अनुमति आवश्यक |
|---|---|---|
Intent.ACTION_DIAL | डायलर खोलता है, नंबर प्री-फिल करता है, उपयोगकर्ता को कॉल बटन दबाना पड़ता है | नहीं |
Intent.ACTION_CALL | सीधे कॉल शुरू करता है | CALL_PHONE (खतरनाक अनुमति) |
विशेष नंबर फॉर्मेट:
- सामान्य:
tel:1234567890 - इंटरनेशनल:
tel:+911234567890 - USSD कोड:
tel:*123%23(#को%23से एनकोड करें) - पॉज/वेट:
tel:1234567890,,1234(,= 2 सेकंड पॉज,;= वेट)