20170304 

ContentResolver-Email

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.example.wata.myapplication">

    <uses-permission android:name="android.permission.READ_CONTACTS" />

    <application

        android:allowBackup="true"

        android:icon="@mipmap/ic_launcher"

        android:label="@string/app_name"

        android:supportsRtl="true"

        android:theme="@style/AppTheme">

        <activity android:name=".MainActivity">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

 

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

    </application>

 

</manifest>

 

//

 

package com.example.wata.myapplication;

 

import android.app.Activity;

import android.content.ContentResolver;

import android.database.Cursor;

import android.net.Uri;

import android.os.Bundle;

import android.provider.ContactsContract;

 

public class MainActivity extends Activity {

        public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

    }

    protected void onResume() {

        super.onResume();

        ContentResolver contentResolver = getContentResolver();

        Uri uri = ContactsContract.CommonDataKinds.Email.CONTENT_URI;

        String[] projection = new String[]{ContactsContract.CommonDataKinds.Email.DATA1};

        String order = ContactsContract.CommonDataKinds.Email.DATA1 + " ASC";

        Cursor cursor = contentResolver.query(uri, projection, null, null, order);

        if (cursor.moveToFirst()) {

            int emailColumn = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA1);

            do {

                System.out.println(cursor.getString(emailColumn));

            } while (cursor.moveToNext());

        }

    }

}