6 package com.google.appinventor.components.runtime.util;
10 import android.app.Activity;
11 import android.content.ContentResolver;
12 import android.content.Context;
13 import android.content.DialogInterface;
15 import android.database.Cursor;
16 import android.net.Uri;
17 import android.provider.ContactsContract;
18 import android.provider.ContactsContract.CommonDataKinds.Email;
19 import android.provider.ContactsContract.CommonDataKinds.Phone;
20 import android.provider.ContactsContract.Data;
22 import java.io.InputStream;
38 return ContactsContract.Contacts.CONTENT_URI;
45 return Phone.CONTENT_URI;
52 return Data.CONTENT_URI;
59 String[] contactProjection = {
60 ContactsContract.Contacts._ID,
61 ContactsContract.Contacts.DISPLAY_NAME_PRIMARY,
62 ContactsContract.Contacts.PHOTO_THUMBNAIL_URI,
63 ContactsContract.Contacts.PHOTO_URI,
65 return contactProjection;
72 String[] nameProjection = {
74 ContactsContract.Contacts.DISPLAY_NAME,
75 ContactsContract.Contacts.PHOTO_THUMBNAIL_URI,
78 return nameProjection;
85 String[] dataProjection = {
92 return dataProjection;
99 String[] emailAdapterProjection = {
105 return emailAdapterProjection;
112 return contactCursor.getColumnIndex(ContactsContract.Contacts._ID);
119 return contactCursor.getColumnIndex(Data.CONTACT_ID);
126 return contactCursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
133 return contactCursor.getColumnIndex(ContactsContract.Contacts.PHOTO_THUMBNAIL_URI);
140 return contactCursor.getColumnIndex(ContactsContract.Contacts.PHOTO_URI);
144 return dataCursor.getColumnIndex(Phone.NUMBER);
148 return dataCursor.getColumnIndex(Email.ADDRESS);
152 return dataCursor.getColumnIndex(Data.MIMETYPE);
158 return Phone.CONTENT_ITEM_TYPE;
165 return Email.CONTENT_ITEM_TYPE;
172 return Data.DISPLAY_NAME;
179 return Email.ADDRESS;
186 return Data.MIMETYPE;
192 public static Cursor
getDataCursor(String
id, Activity activityContext, String[] dataProjection) {
193 Cursor dataCursor = activityContext.getContentResolver().query(
196 Data.CONTACT_ID +
"=? AND (" + Data.MIMETYPE +
"=? OR " + Data.MIMETYPE +
"=?)",
197 new String[] {id, Phone.CONTENT_ITEM_TYPE, Email.CONTENT_ITEM_TYPE},
206 return ContactsContract.Contacts.openContactPhotoInputStream(cr, contactUri);
213 return Data.TIMES_CONTACTED;