0

我正在尝试将 sd 卡中的 mp3 歌曲设置为特定联系人的铃声。我正在设置的所有值,但未设置铃声。这是我的代码:

public void onActivityResult(int reqCode, int resultCode, Intent data) {
    super.onActivityResult(reqCode, resultCode, data);

    switch (reqCode) {
    case (PICK_CONTACT):
        if (resultCode == Activity.RESULT_OK) {

            Uri contactData = data.getData();
            Cursor c = managedQuery(contactData, null, null, null, null);
            if (c.moveToFirst()) {

                String id = c
                        .getString(c
                                .getColumnIndexOrThrow(ContactsContract.Contacts._ID));
                // set custom ringtone to this id
                Uri localUri = Uri.withAppendedPath(
                        ContactsContract.Contacts.CONTENT_URI, id);
                ContentValues localContentValues = new ContentValues();

                String hasPhone = c
                        .getString(c
                                .getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));

                if (hasPhone.equalsIgnoreCase("1")) {
                    Cursor phones = getContentResolver()
                            .query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                                    null,
                                    ContactsContract.CommonDataKinds.Phone.CONTACT_ID
                                            + " = " + id, null, null);
                    phones.moveToFirst();
                    String cNumber = phones.getString(phones
                            .getColumnIndex("data1"));
                    System.out.println("number is:" + cNumber);

                }

                String name = c
                        .getString(c
                                .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                String SDCardRoot1 = (Environment
                        .getExternalStorageDirectory() + "/cocktail.mp3");

                localContentValues.put(
                        ContactsContract.Data.RAW_CONTACT_ID, id);
                localContentValues.put(
                        ContactsContract.Data.CUSTOM_RINGTONE, SDCardRoot1);
                getContentResolver().update(localUri, localContentValues,
                        null, null);
                Toast.makeText(this, "Ringtone assigned to: " + name, 0)
                        .show();

                // Toast.makeText(getApplicationContext(), name,
                // 1000).show();

            }
        }
        break;
    }
}

我已经尝试了很多,但没有得出任何结论。请帮助我。

4

0 回答 0