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.xml
<?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.Java
package com.androidian.quickcontact;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.widget.QuickContactBadge;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView Email,Phone;
QuickContactBadge EmailPic,PhonePic;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Email = (TextView)findViewById(R.id.textView1);
Phone = (TextView)findViewById(R.id.textView2);
EmailPic = (QuickContactBadge)findViewById(R.id.quickContactBadge1);
PhonePic = (QuickContactBadge)findViewById(R.id.quickContactBadge2);
//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);
}
}