1

这是我用来获取分配给联系人的自定义铃声的代码。但是,如果该联系人属于某个组,并且该组有自定义铃声,我怎样才能获得该组的自定义铃声?

谢谢

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

public String getCustomRingtoneOfContact(String number) {
    if (number.length() == 0) return null;
    Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
    String sTone;

    Cursor contactLookup = Contexto.getContentResolver().query(uri, new String[] {BaseColumns._ID, ContactsContract.PhoneLookup.DISPLAY_NAME, ContactsContract.PhoneLookup.CUSTOM_RINGTONE}, null, null, null);

     try {
        if (contactLookup != null && contactLookup.getCount() > 0) {
            contactLookup.moveToNext();
            //String sName = contactLookup.getString(contactLookup.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
            //String contactId = contactLookup.getString(contactLookup.getColumnIndex(BaseColumns._ID));
            sTone = contactLookup.getString(contactLookup.getColumnIndex(ContactsContract.Data.CUSTOM_RINGTONE));      
        }
     } finally {
        if (contactLookup != null) {
            contactLookup.close();
        }
     }

     return sTone;
}
4

0 回答 0