0

I am developing an android app for customizing contact configuration. In which I have to set different ringer mode for each contact. Can anyone help me ??? Thanks in advance..

Once again I confirm that I am not asking about ringtone. I am asking about ringer profile (that are normal, vibrate and silent). How can I set different ringer profile for each contact. I have already implemented the database.

Shahbaz Hashmi
  • 2,631
  • 2
  • 26
  • 49
  • possible duplicate of [Set as Contact Ringtone? Android](http://stackoverflow.com/questions/23410946/set-as-contact-ringtone-android) – rds Apr 06 '15 at 09:48

1 Answers1

0

Try the following:

1- Have listener detecting when a phone call is happening. http://bitgriff.blogspot.com/2013/01/detecting-incoming-and-outgoing-phone.html

2-Then according the the caller, you can set the ringer mode from silent to vibrate or a ringtone.

AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);

Check AudioManager documentation for other RingerMode

Link: http://developer.android.com/reference/android/media/AudioManager.html

**Changing Ringtone, not mode:

Basically what you have to do is the following:

1- Get the contact lookup Uri

2- Get the Uri of the ringtone that you want to set

3- Use ContentValues in order to update the ringtone

Check this question in order to achieve a custom ringtone for a contact: Set as Contact Ringtone? Android

This is another good reference: Setting contact custom ringtone, how?

Community
  • 1
  • 1
Ziad Halabi
  • 964
  • 11
  • 31
  • Custom ringtone is also feature of my app. And I have implemented custom ringtone for contact. Can I set Audio manager ringer mode for each contact ? Or can you tell how to set up vibrate ringtone or silent ringtone as custom ringtone of contact ? Thanks for your reply. – Shahbaz Hashmi Apr 06 '15 at 09:58
  • I am sorry I didnt quite understand what you are asking for. Can you paraphrase: "Can I set Audio manager ringer mode for each contact ?" And your second question, you mean instead of selecting a song ringtone, you want to just make it vibrate or silent? – Ziad Halabi Apr 06 '15 at 10:03
  • Yeah, I am talking about ringer profile. That are normal, vibrate and silent – Shahbaz Hashmi Apr 06 '15 at 10:07
  • Take a look at Audio Manager documentation, there are useful functions such as setVibrateSetting(int vibrateType, int vibrateSetting). One trick that you can do is have a mp3 audio file that is completely silent and assign it as a ringtone for a contact. – Ziad Halabi Apr 06 '15 at 10:14
  • Is there a file for vibration also ? How can I attach these mp3 file with my application. Can you please provide me the code for set ringtone as ContactsContract.CommonDataKinds.Phone.CUSTOM_RINGTONE – Shahbaz Hashmi Apr 06 '15 at 10:24
  • You need to include these mp3 files in a folder in your project under res folder and call it raw. Then, in your app u can get these files by referring to their id, for example R.raw.ringtone Please refer to the links for code samples. – Ziad Halabi Apr 06 '15 at 10:41
  • Please provide me the code that how I set R.raw.ringtone1 as ContactsContract.CommonDataKinds.Phone.CUSTOM_RINGTONE. Thanks.. – Shahbaz Hashmi Apr 06 '15 at 11:02
  • Check my modified answer – Ziad Halabi Apr 06 '15 at 11:24
  • Your welcome, good luck with your App! Please upvote/accept my answer. – Ziad Halabi Apr 06 '15 at 16:19