Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> Android

Android ऐप में नए कॉन्टैक्ट कैसे जोड़ें?

Android ऐप में नए कॉन्टैक्ट जोड़ना

यह उदाहरण दर्शाता है कि Android ऐप में नए कॉन्टैक्ट कैसे जोड़े जाते हैं।

चरण 1 - नया प्रोजेक्ट बनाएं

Android Studio में File → New Project पर जाएं और नया प्रोजेक्ट बनाने के लिए सभी आवश्यक विवरण भरें।

चरण 2 - res/layout/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:layout_margin="16dp"
    android:orientation="vertical"
    tools:context=".MainActivity">
    <EditText
        android:id="@+id/etContactName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Contact name"
        android:inputType="text" />
    <EditText
        android:id="@+id/etContactNumber"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Contact number"
        android:inputType="number" />
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="addContact"
        android:text="ADD" />
</LinearLayout>

चरण 3 - src/MainActivity.java में कोड जोड़ें

package app.tutorialspoint.com.sample;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void addContact(View view) {
        EditText etContactName = findViewById(R.id.etContactName);
        EditText etContactNumber = findViewById(R.id.etContactNumber);
        String name = etContactName.getText().toString();
        String phone = etContactNumber.getText().toString();
        Intent contactIntent = new Intent(ContactsContract.Intents.Insert.ACTION);
        contactIntent.setType(ContactsContract.RawContacts.CONTENT_TYPE);
        contactIntent
                .putExtra(ContactsContract.Intents.Insert.NAME, name)
                .putExtra(ContactsContract.Intents.Insert.PHONE, phone);
        startActivityForResult(contactIntent, 1);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        if (requestCode == 1) {
            if (resultCode == Activity.RESULT_OK) {
                Toast.makeText(this, "Added Contact", Toast.LENGTH_SHORT).show();
            }
            if (resultCode == Activity.RESULT_CANCELED) {
                Toast.makeText(this, "Cancelled Added Contact", Toast.LENGTH_SHORT).show();
            }
        }
    }
}

चरण 4 - AndroidManifest.xml में कोड जोड़ें

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
    package="app.tutorialspoint.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>
        <receiver
            android:name=".DeviceAdmin"
            android:description="@string/app_description"
            android:label="@string/app_name"
            android:permission="android.permission.BIND_DEVICE_ADMIN">
            <meta-data
                android:name="android.app.device_admin"
                android:resource="@xml/policies" />
            <intent-filter>
                <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
            </intent-filter>
        </receiver>
    </application>
</manifest>

एप्लिकेशन चलाएं

अपने Android डिवाइस को कंप्यूटर से कनेक्ट करें। Android Studio से ऐप चलाएं और अपने मोबाइल डिवाइस पर डिफ़ॉल्ट स्क्रीन देखें।


  1. Android में PreferenceScreen पर बटन कैसे जोड़ें? Android में PreferenceScreen पर बटन कैसे जोड़ें?

    AndroidX Preference लाइब्रेरी का उपयोग करके सेटिंग्स स्क्रीन में कस्टम एक्शन बटन जोड़ने का तरीका। चरण 1: नया प्रोजेक्ट बनाएं Android Studio में नया प्रोजेक्ट बनाएं। चरण 2: एक्टिविटी लेआउट res/layout/activity_main.xml - Fragment कंटेनर: <LinearLayout xmlns:android=https://schemas.android.com/apk

  1. एंड्रॉइड ऐप में कैलेंडर इवेंट कैसे जोड़ें एंड्रॉइड ऐप में कैलेंडर इवेंट कैसे जोड़ें

    इंटेंट के माध्यम से सिस्टम कैलेंडर ऐप में इवेंट जोड़ना एंड्रॉइड में कैलेंडर इवेंट जोड़ने का सबसे सरल तरीका Intent.ACTION_INSERT या Intent.ACTION_EDIT का उपयोग करके सिस्टम कैलेंडर ऐप को लॉन्च करना है। यह यूजर को इवेंट विवरण संपादित/पुष्टि करने देता है और किसी विशेष अनुमति की आवश्यकता नहीं होती। चरण

  1. Android Studio में JAR फ़ाइल को लाइब्रेरी के रूप में कैसे जोड़ें? Android Studio में JAR फ़ाइल को लाइब्रेरी के रूप में कैसे जोड़ें?

    यह गाइड बताता है कि Android Studio प्रोजेक्ट में बाहरी JAR फ़ाइल को लाइब्रेरी के रूप में कैसे जोड़ा जाता है। चरण 1: नया प्रोजेक्ट बनाएं Android Studio में File → New Project पर जाएं और प्रोजेक्ट बनाएं। चरण 2: JAR फ़ाइल को libs फ़ोल्डर में कॉपी करें Project व्यू में app/libs फ़ोल्डर खोलें (नहीं है