Fetch Contact List from android device

How to fetch Contact list in android to use it in own way. The android OS provides feature to fetch all contacts from android device like Name, Image, Phone No., Email Id. It fetches all contacts from all added accounts like Facebook, Gmail, Watsapp and your android device which stores contacts. This tutorial is about to fetch contact list from an android device.

This example uses the ContactsContract and ContentResolver classes to fetch all contacts from android device. The URI used is CONTENT_URI to fetch contacts.
ContentResolver cr = this.getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (cur.moveToNext()) {
String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
image_uri = cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_URI));
if (Integer.parseInt( cur.getString( cur.getColumnIndex( ContactsContract.Contacts.HAS_PHONE_NUMBER ) ) ) > 0) {
Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { id }, null);
while (pCur.moveToNext()) {
phone = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
pCur.close();
Cursor emailCur = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?", new String[] { id }, null);
int e = 0;
while (emailCur.moveToNext()) {
emailContact = emailCur.getString(emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
}
}
}

The above given code will help to fetch all contacts from android device.

Detect Android App Webview in Php




Sometimes we have an app with webview in android where we use our website as app in android. Where to hold website we use android webview. To identify or detect the app in php websites we need to solve the situation. To do this php provides a predefined variable :
 $_SERVER['HTTP_X_REQUESTED_WITH']

This variable matches the package name of android app to identify if user is using our android app or using website.




Example is given below : 
if($_SERVER['HTTP_X_REQUESTED_WITH'] == "com.sk.codes") {
echo 'Welcome to Basic Codes android app.';
}