Quick contact badge is gives us the way to add any contact information directly through android application to mobile phone. Quick contact badge is basically used in information and advice apps because with this feature application user can naively store given contact number, email without completing copying process. QuickContactBadge will save the contact using one click contact integration.
activity_main.kt
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="38dp"
android:text="Email Contact" />
<QuickContactBadge
android:id="@+id/quickContactBadge1"
android:layout_width="100sp"
android:layout_height="100sp"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"
android:src="@drawable/b" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Phone Contact" />
<QuickContactBadge
android:id="@+id/quickContactBadge2"
android:layout_width="100sp"
android:layout_height="100sp"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:src="@drawable/c" />
</RelativeLayout>
MainActivity.kt
package com.androidian.quickcontact
import android.os.Bundle
import android.provider.ContactsContract
import android.view.View
import android.widget.QuickContactBadge
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
var Email: TextView? = null
var Phone: TextView? = null
var EmailPic: QuickContactBadge? = null
var PhonePic: QuickContactBadge? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Email = findViewById<View>(R.id.textView1) as TextView
Phone = findViewById<View>(R.id.textView2) as TextView
EmailPic = findViewById<View>(R.id.quickContactBadge1) as QuickContactBadge
PhonePic = findViewById<View>(R.id.quickContactBadge2) as QuickContactBadge
//Assign the contact badge to Email Pick badge.
EmailPic!!.assignContactFromEmail("android@examples.com", true)
EmailPic!!.setMode(ContactsContract.QuickContact.MODE_MEDIUM)
//Assign the contact badge to phone pick badge.
PhonePic!!.assignContactFromPhone("+911234567890", true)
PhonePic!!.setMode(ContactsContract.QuickContact.MODE_MEDIUM)
}
}