Open contacts activity from your app

Navigation between applications in Android it’s smooth. You can go back and forward through activities without noticing which are built in and which are not.

The example below will show you a way of selecting a contact from your application, but first starting the built in functionality and then passing into your app the selected item, in our case only the display name.

 

Button click handler that will open Contact activity

private OnClickListener onClickPickContact = new OnClickListener() {

@Override
public void onClick(View arg0) {
Intent intent = new Intent(Intent.ACTION_PICK,
ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, 0);
}
};

 

How to grab that picked contact and show it in a toast over the screen

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if (resultCode == Activity.RESULT_OK && requestCode == 0) {
Cursor cursor = getContentResolver().query(data.getData(),
new String[] { ContactsContract.Contacts.DISPLAY_NAME },
null, null, null);

if (cursor.moveToFirst()) {
int columnIndex = cursor
.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
String name = cursor.getString(columnIndex);
Toast.makeText(getApplicationContext(), name, Toast.LENGTH_LONG)
.show();
}
}

};

Create a shape in Android

Web

All about Shapes can be found here. A simplest example of how to create a shape is the code snippet below. Save this xml under the drawable folder.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#FFFF0000"
android:endColor="#80FF00FF"
android:angle="45"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<corners android:radius="8dp" />
</shape>

To use this shape, just set the background property of an layout element using the “@drawable/shape_file_name”.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/colors"
android:layout_width="match_parent">
</RelativeLayout>

 

 image