当前位置: 首页>>代码示例>>Java>>正文


Java Contacts类代码示例

本文整理汇总了Java中android.provider.Contacts的典型用法代码示例。如果您正苦于以下问题:Java Contacts类的具体用法?Java Contacts怎么用?Java Contacts使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Contacts类属于android.provider包,在下文中一共展示了Contacts类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getContactPhoneIntent

import android.provider.Contacts; //导入依赖的package包/类
public static Intent getContactPhoneIntent() {
    Intent intent = new Intent(Intent.ACTION_PICK);
    /*
     * intent.setAction(Intent.ACTION_GET_CONTENT);
     * intent.setType(Contacts.Phones.CONTENT_ITEM_TYPE);
     */
    if (isCompatible(5)) {
        // Don't use constant to allow backward compat simply
        intent.setData(Uri.parse("content://com.android.contacts/contacts"));
    } else {
        // Fallback for android 4
        intent.setData(Contacts.People.CONTENT_URI);
    }

    return intent;

}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:18,代码来源:Compatibility.java

示例2: create

import android.provider.Contacts; //导入依赖的package包/类
public void create(Contact newPhoneContact) throws Exception {
    // first, we have to create the contact
    ContentValues newPhoneValues = new ContentValues();
    newPhoneValues.put(Contacts.People.NAME, newPhoneContact.getName());
    Uri newPhoneRow = resolver.insert(Contacts.People.CONTENT_URI, newPhoneValues);

    // then we have to add a number
    newPhoneValues.clear();
    newPhoneValues.put(Contacts.People.Phones.TYPE, Contacts.People.Phones.TYPE_MOBILE);
    newPhoneValues.put(Contacts.Phones.NUMBER, newPhoneContact.getNumber());
    // insert the new phone number in the database using the returned uri from creating the contact
    newPhoneRow = resolver.insert(Uri.withAppendedPath(newPhoneRow, Contacts.People.Phones.CONTENT_DIRECTORY), newPhoneValues);

    // if contacts uri returned, there was an error with adding the number
    if (newPhoneRow.getPath().contains("people")) {
        throw new Exception(String.valueOf(R.string.error_phone_number_not_stored));
    }

    // if phone uri returned, everything went OK
    if (!newPhoneRow.getPath().contains("phones")) {
        // some unknown error has happened
        throw new Exception(String.valueOf(R.string.error_phone_number_error));
    }
}
 
开发者ID:yeriomin,项目名称:DumbphoneAssistant,代码行数:25,代码来源:PhoneUtilDonut.java

示例3: retrieveContactUri

import android.provider.Contacts; //导入依赖的package包/类
public Uri retrieveContactUri(Contact contact) {
    String id = contact.getId();
    String[] projection = new String[] { Contacts.Phones.PERSON_ID };
    String path = null;
    Cursor result;
    if (null != id) {
        Uri uri = ContentUris.withAppendedId(Contacts.Phones.CONTENT_URI, Long.valueOf(id));
        result = resolver.query(uri, projection, null, null, null);
    } else {
        String selection = "name='?' AND number='?'";
        String[] selectionArgs = new String[] { contact.getName(), contact.getNumber() };
        result = resolver.query(Contacts.Phones.CONTENT_URI, projection, selection, selectionArgs, null);
    }
    if (null != result) {
        result.moveToNext();
        path = result.getString(0);
        result.close();
    }
    if (null == path) {
        return null;
    }
    return Uri.withAppendedPath(Contacts.People.CONTENT_URI, path);
}
 
开发者ID:yeriomin,项目名称:DumbphoneAssistant,代码行数:24,代码来源:PhoneUtilDonut.java

示例4: getAllContactsPhoneNumbers

import android.provider.Contacts; //导入依赖的package包/类
@Override
public String getAllContactsPhoneNumbers(Activity activity) {
    StringBuilder sb = new StringBuilder(1024);

    String[] PROJECTION = new String[] {
        PhonesColumns.NUMBER
    };

    Cursor c = activity.managedQuery(Contacts.Phones.CONTENT_URI, PROJECTION, null, null,
            Contacts.Phones.DEFAULT_SORT_ORDER);

    if (c.moveToFirst()) {
        sb.append(c.getString(0));
        while (c.moveToNext()) {
            sb.append(",");
            sb.append(c.getString(0));
        }
    }
    c.close();

    return sb.toString();
}
 
开发者ID:Kamshak,项目名称:foursquared,代码行数:23,代码来源:AddressBookUtils3and4.java

示例5: getAllContactsEmailAddresses

import android.provider.Contacts; //导入依赖的package包/类
@Override
public String getAllContactsEmailAddresses(Activity activity) {
    StringBuilder sb = new StringBuilder(1024);
    
    String[] PROJECTION = new String[] { 
        Contacts.ContactMethods.DATA
    }; 

    Cursor c = activity.managedQuery(
            Contacts.ContactMethods.CONTENT_EMAIL_URI, 
            PROJECTION, null, null, 
            Contacts.ContactMethods.DEFAULT_SORT_ORDER); 
    
    if (c.moveToFirst()) {
        sb.append(c.getString(0));
        while (c.moveToNext()) {
            sb.append(",");
            sb.append(c.getString(0));
        }
    }
    c.close();
    
    return sb.toString();
}
 
开发者ID:Kamshak,项目名称:foursquared,代码行数:25,代码来源:AddressBookUtils3and4.java

示例6: getContacts

import android.provider.Contacts; //导入依赖的package包/类
public String[] getContacts(Context context, boolean withNumbers) {
    Vector ids = new Vector();

    String selection = null;
    if (withNumbers) {
        selection = ContactsContract.Contacts.HAS_PHONE_NUMBER + "=1";
    }

    Cursor cursor = context.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, selection, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");
    while (cursor.moveToNext()) {
        String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
        ids.add(contactId);
    }
    cursor.close();

    String[] contacts = new String[ids.size()];
    for (int i = 0; i < ids.size(); i++) {
        String id = (String) ids.elementAt(i);
        contacts[i] = id;
    }
    return contacts;
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:23,代码来源:AndroidContactsManager.java

示例7: getContacts

import android.provider.Contacts; //导入依赖的package包/类
public String[] getContacts(Activity context, boolean withNumbers) {
    Vector ids = new Vector();

    String selection = null;
    if (withNumbers) {
        selection = ContactsContract.Contacts.HAS_PHONE_NUMBER + "=1";
    }

    Cursor cursor = context.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, selection, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");
    while (cursor.moveToNext()) {
        String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
        ids.add(contactId);
    }
    cursor.close();

    String[] contacts = new String[ids.size()];
    for (int i = 0; i < ids.size(); i++) {
        String id = (String) ids.elementAt(i);
        contacts[i] = id;
    }
    return contacts;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:23,代码来源:AndroidContactsManager.java

示例8: doesUriContainLocationInfo

import android.provider.Contacts; //导入依赖的package包/类
public static boolean doesUriContainLocationInfo(Context ctx, Uri uri) throws RuntimeException {
	//Log.d(TAG, "uri.toString()=="+uri.toString());

	final int sdkVersion = Integer.parseInt( Build.VERSION.SDK ); // Build.VERSION.SDK_INT was introduced after API level 3 and so is not compatible with 1.5 devices.
	
	if( 5 > sdkVersion ){ // Anrdoid 1.x series code.
		if(uri.toString().startsWith(android.provider.Contacts.People.CONTENT_URI.toString())){
			return LocationUtil.doesContactUriContainLocationInfoSDK3(ctx, uri);
		}else{
			return false;
		}
		
	}else{ // Android 2.x series code.
		if(uri.toString().startsWith("content://com.android.contacts/contacts/lookup")){
			return LocationUtil.doesContactUriContainLocationInfoSDK5(ctx, uri);
		}else{
			return false;
		}			
	}			
}
 
开发者ID:SpencerRiddering,项目名称:flingtap-done,代码行数:21,代码来源:LocationUtil.java

示例9: getLabelsForKind

import android.provider.Contacts; //导入依赖的package包/类
static String[] getLabelsForKind(Context context, int kind) {
    	final Resources resources = context.getResources();
    	switch (kind) {
    		case Contacts.KIND_PHONE:
    			return resources.getStringArray(android.R.array.phoneTypes);
    		case Contacts.KIND_EMAIL:
    			return resources.getStringArray(android.R.array.emailAddressTypes);	
    		case Contacts.KIND_POSTAL:
    			return resources.getStringArray(android.R.array.postalAddressTypes);
    		case Contacts.KIND_IM:
    			return resources.getStringArray(android.R.array.imProtocols);
    		case Contacts.KIND_ORGANIZATION:
    			return resources.getStringArray(android.R.array.organizationTypes);
//    		case EditEntry.KIND_CONTACT:
//    			return resources.getStringArray(R.array.otherLabels);
    	}
    	return null;
    }
 
开发者ID:SpencerRiddering,项目名称:flingtap-done,代码行数:19,代码来源:ContactsListActivity.java

示例10: ContactItemListAdapter

import android.provider.Contacts; //导入依赖的package包/类
public ContactItemListAdapter(Context context) {
            super(context, R.layout.contacts_list_item, null, false);
            mContext = context;
            mAlphabet = context.getString(R.string.fast_scroll_alphabet); // com.android.internal. 
            
            mUnknownNameText = context.getText(android.R.string.unknownName);
            switch (mMode) {
                case MODE_PICK_POSTAL:
                    mLocalizedLabels = getLabelsForKind(mContext,
                            Contacts.KIND_POSTAL);
                    break;
                default:
                    mLocalizedLabels = getLabelsForKind(mContext,
                            Contacts.KIND_PHONE);
                    break;
            }
            
//            if ((mMode & MODE_MASK_SHOW_PHOTOS) == MODE_MASK_SHOW_PHOTOS) {
//                mDisplayPhotos = true;
//                setViewResource(R.layout.contacts_list_item_photo);
//                mBitmapCache = new SparseArray<SoftReference<Bitmap>>();
//            }
        }
 
开发者ID:SpencerRiddering,项目名称:flingtap-done,代码行数:24,代码来源:ContactsListActivity.java

示例11: getPersonIdFromPhoneNumber

import android.provider.Contacts; //导入依赖的package包/类
/**
 * Looks up a contacts id, given their address (phone number in this case).
 * Returns null if not found
 */
public static String getPersonIdFromPhoneNumber(Context context, String address) {
	if (address == null)
		return null;

	Cursor cursor = context.getContentResolver().query(
			Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, address),
			new String[] { Contacts.Phones.PERSON_ID }, null, null, null);
	if (cursor != null) {
		try {
			if (cursor.getCount() > 0) {
				cursor.moveToFirst();
				Long id = Long.valueOf(cursor.getLong(0));
				// Log.v("Found person: " + id);
				return (String.valueOf(id));
			}
		} finally {
			cursor.close();
		}
	}
	return null;
}
 
开发者ID:r00li,项目名称:RHome,代码行数:26,代码来源:SmsPopupUtils.java

示例12: isExcludedType

import android.provider.Contacts; //导入依赖的package包/类
boolean isExcludedType(Vector<Integer> vExTypesCode, String sNumber, Context oContext)
  {
  	Uri contactRef = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, sNumber);
  	final String[] PHONES_PROJECTION = new String[] 
   {
       People.Phones.NUMBER, // 0
       People.Phones.TYPE, // 1
   };
      Cursor phonesCursor = oContext.getContentResolver().query(contactRef, PHONES_PROJECTION, null, null,
              null);
if (phonesCursor != null) 
      {	        			
           while (phonesCursor.moveToNext()) 
          { 			            	
              final int type = phonesCursor.getInt(1);	              
              if(vExTypesCode.contains(Integer.valueOf(type)))
              	return true;	    
          }
          phonesCursor.close();
      }
return false;
  }
 
开发者ID:bigbn,项目名称:phonty,代码行数:23,代码来源:Caller.java

示例13: startQuery

import android.provider.Contacts; //导入依赖的package包/类
/**
  * Factory method to start query with a number
  */
 public static CallerInfoAsyncQuery startQuery(int token, Context context, String number, String number2, 
         OnQueryCompleteListener listener, Object cookie) {
     //contruct the URI object and start Query.
 	String number_search = number;
     if (number.contains("&"))
     	number_search = number.substring(0,number.indexOf("&"));
     Uri contactRef = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, number_search);
     
     CallerInfoAsyncQuery c = new CallerInfoAsyncQuery();
     c.allocate(context, contactRef);

     if (DBG) log("starting query for number: " + number + " handler: " + c.toString());
     
     //create cookieWrapper, start query
     CookieWrapper cw = new CookieWrapper();
     cw.listener = listener;
     cw.cookie = cookie;
     cw.number = number;
     cw.number2 = number2;

     cw.event = EVENT_NEW_QUERY;
     c.mHandler.startQuery (token, cw, contactRef, null, null, null, null);
     
     return c;
}
 
开发者ID:bigbn,项目名称:phonty,代码行数:29,代码来源:CallerInfoAsyncQuery.java

示例14: getContact

import android.provider.Contacts; //导入依赖的package包/类
public CallerIDResult getContact(String phoneNumber) throws NoResultException {
	final Uri uri = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, Uri.encode(phoneNumber));
	final ContentResolver contentResolver = application.getContentResolver();
	final Cursor cursor = contentResolver.query(uri,GET_CONTACT_PROJECTION,null,null,null);
	try{
		if(cursor.moveToNext()){
			CallerIDResult ret = new CallerIDResult();
			ret.setPhoneNumber(cursor.getString(NUMBER_COLUMN_INDEX));
			ret.setName(cursor.getString(DISPLAY_NAME_COLUMN_INDEX));
			return ret;
		}else{
			throw new NoResultException();
		}
	}finally{
		cursor.close();
	}
}
 
开发者ID:candrews,项目名称:callerid-for-android,代码行数:18,代码来源:OldContactsHelper.java

示例15: addContact

import android.provider.Contacts; //导入依赖的package包/类
final void addContact(String[] names, String[] phoneNumbers, String[] emails, String note,
                       String address, String org, String title) {

  // Only use the first name in the array, if present.
  Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT, Contacts.CONTENT_URI);
  intent.setType(Contacts.People.CONTENT_ITEM_TYPE);
  putExtra(intent, Contacts.Intents.Insert.NAME, names != null ? names[0] : null);

  int phoneCount = Math.min(phoneNumbers != null ? phoneNumbers.length : 0,
      Contents.PHONE_KEYS.length);
  for (int x = 0; x < phoneCount; x++) {
    putExtra(intent, Contents.PHONE_KEYS[x], phoneNumbers[x]);
  }

  int emailCount = Math.min(emails != null ? emails.length : 0, Contents.EMAIL_KEYS.length);
  for (int x = 0; x < emailCount; x++) {
    putExtra(intent, Contents.EMAIL_KEYS[x], emails[x]);
  }

  putExtra(intent, Contacts.Intents.Insert.NOTES, note);
  putExtra(intent, Contacts.Intents.Insert.POSTAL, address);
  putExtra(intent, Contacts.Intents.Insert.COMPANY, org);
  putExtra(intent, Contacts.Intents.Insert.JOB_TITLE, title);
  launchIntent(intent);
}
 
开发者ID:saqimtiaz,项目名称:BibSearch,代码行数:26,代码来源:ResultHandler.java


注:本文中的android.provider.Contacts类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。