To open the default contact for android, use this code:
// put that constant in your class static public final int CONTACT_CHOOSER_ACTIVITY_CODE = 73729; // start contact search activity within any method you like Intent intent = new Intent(Intent.ACTION_PICK); intent.setType(ContactsContract.Contacts.CONTENT_TYPE); startActivityForResult(intent, CONTACT_CHOOSER_ACTIVITY_CODE);
In the onActivityResult method, you can use this code (similar to Rotary Heart ) to set the ringtone:
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case (CONTACT_CHOOSER_ACTIVITY_CODE) : if (resultCode == Activity.RESULT_OK) { try{ Uri contactData = data.getData(); String contactId = contactData.getLastPathSegment(); String[] PROJECTION = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.HAS_PHONE_NUMBER, }; Cursor localCursor = getContentResolver().query(contactData, PROJECTION, null, null, null); localCursor.moveToFirst();
Note: you still need to set the f variable (in the code f.getAbsolutePath () + "/Adventure.ogg") to your file (ringtone) that you want to set.
This code has been tested with Android 2.3. Perhaps higher versions require changes.
source share