Android QuickContactBadge example tutorial

Store email, phone number contact from application to phone.

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. So here is the complete step by step tutorial for Android QuickContactBadge example tutorial.

android-project-download-code-button

Android QuickContactBadge example tutorial.

Code for MainActivity.java file.

package com.android_examples.com.quickcontactbadge;
import android.app.Activity;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.widget.QuickContactBadge;
import android.widget.TextView;

public class MainActivity extends Activity {

 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("[email protected]", 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);
 
 

 }
}

Code for activity_main.xml layout file.

<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"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.android_examples.com.quickcontactbadge.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>

Screenshots:

add contacts Android QuickContactBadge example tutorial

Click Here to Download Android QuickContactBadge example tutorial project.

Leave a Reply

Your email address will not be published. Required fields are marked *