Setting Ringtones for Android development

Source: Internet
Author: User

First Introduce Android the system supports the ringtone format. There are several types of the following :

64 Hz MIDI,AAC, aac+, AMR, WAV, MP3, Real Audio, WMA, OGG and other formats.

Setting the audio file to a ringtone is simple, just a few steps away:

1) get the URI of the system audio file

Uri Uri =mediastore.audio.media. Getcontenturiforpath (File.getabsolutepath ()); // gets the URI of the system audio file

2) Insert the file into the System Media Library and get the new URI

Uri Newuri = this. Getcontentresolver (). Insert (uri,values); // Insert the file into the System Media Library and get the new URI

3) set the ringtone

Ringtonemanager. Setactualdefaultringtoneuri (This, Ringtype, Newuri); // Set Ringtones

Here is the detailed code for setting the ringtone:

/** * Set ringtone * @param ringtype int: Ringtone type * @param file file: Files to be set as ringtones * */protected void setringtone (int ringtype, file file ) {//TODO auto-generated method Stubboolean Isringtone=false,isnotification=false,isalarm=false,ismusic=false; String msg= ""; switch (ringtype) {case constutil.ring_alarm://alarm isalarm=true;msg= "Set alarm ringtone! "; break;case constutil.ring_notification://notification isnotification=true;msg=" set notification ringtone success! "; break;case constutil.ring_ringtone://call isringtone=true;msg=" set the incoming ringtone success! "; case constutil.ring_music://add to Ringtone library (all ringtones) ismusic=true;msg=" Set all ringtones 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 ());//Get Uriuri of the system audio file Newuri = This.getcontentresolver (). Insert (URI, values);//Inserts the file into the System Media Library and gets the new Uriringtonemanager.setactualdefaultringtoneuri ( This,ringtype, Newuri);//Set Ringtone Toast.maketext (Getapplicationcontext (), Msg,toast.length_short). Show ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.