Set ringtones for Android development and ringtones for android Development
First, we will introduce the supported ringtone formats in Android. There are the following types:
64Hz Midi, AAC, AAC +, AMR, WAV, MP3, Real Audio, WMA, OGG, and other formats.
It is easy to set the audio file as a ringtone, just a few steps:
1) obtain the Uri of the system audio file
Uri uri = MediaStore. Audio. Media.GetContentUriForPath(File. getAbsolutePath (); // obtain the Uri of the system audio file
2) insert the file into the system library and obtain the new Uri.
Uri newUri =This. GetContentResolver (). insert (uri, values); // insert the file into the system media library and obtain the new Uri.
3) set the ringtone
RingtoneManager.SetActualDefaultRingtoneUri(This, RingType, newUri); // set the ringtone
The following code sets the ringtone:
/*** Set the ringtone * @ param ringType int: the ringtone type * @ param file File: the File to be set as the ringtone **/protected void setRingtone (int ringType, file) {// TODO Auto-generated method stubboolean isRingtone = false, isNotification = false, isAlarm = false, isMusic = false; String msg = ""; switch (ringType) {case ConstUtil. RING_ALARM: // isAlarm = true; msg = "set the alarm tone! "; Break; case ConstUtil. RING_NOTIFICATION: // notification isNotification = true; msg =" Notification ringtone set successfully! "; Break; case ConstUtil. RING_RINGTONE: // call isRingtone = true; msg =" the incoming call ringtone is set successfully! "; Case ConstUtil. RING_MUSIC: // added to the ringtone Library (all ringtones) isMusic = true; msg =" All ringtones are set successfully! "; Break; default: break;} ContentValues values = new ContentValues (); values. put (MediaStore. mediaColumns. DATA, file. getAbsolutePath (); values. put (MediaStore. mediaColumns. TITLE, file. getName (); values. put (MediaStore. mediaColumns. MIME_TYPE, "audio/*"); values. put (MediaStore. audio. media. IS_RINGTONE, isRingtone); values. put (MediaStore. audio. media. IS_NOTIFICATION, isNotification); values. put (MediaStore. audio. media. IS_ALARM, isAlarm); values. put (MediaStore. audio. media. IS_MUSIC, isMusic); Uri uri = MediaStore. audio. media. getContentUriForPath (file. getAbsolutePath (); // obtain the UriUri newUri of the system audio file = this. getContentResolver (). insert (uri, values); // insert the file into the system media library and obtain the new UriRingtoneManager. setActualDefaultRingtoneUri (this, ringType, newUri); // set the Toast. makeText (getApplicationContext (), msg, Toast. LENGTH_SHORT ). show ();}
Set ringtones for android apps
How to create your own ringtone system is written in the book "Unveiling secrets" in android Application Development. It seems that several files need to be created in this path. sys/media/ringtone is the path of music media, and then add it. You can search for it ~~
How to Set ringtones for Android phones
Ringtones are easy to set. Generally, four ringtones can be set for Android phones.
They are calls, text messages, alarm clocks, system ringtones, etc.
The specific setting method is as follows:
1. First open the memory chuck of the Android phone, create a "media" folder in it, and then create a "audio" folder.
2. open the "audio" folder and create "ringtones" (incoming calls), "notifications" (SMS), and "alarms" (alarm clock), "ui" (system prompt ).
3. Store the ringtones in these folders as needed. Restart your phone!
4. Open your Android phone and choose "menu"-"set"-"sound.
[Note: After the folder is created, put the ringtone you want to set in the specified folder, restart your phone, and find the ringtone you want to set in the settings! (How to set SMS ringtones → enter SMS → press menu → enter settings → you can set SMS ringtones )]