My Android Advanced tour------>android system to set default call tones, alarm tones, notification ringtones

Source: Internet
Author: User

Start by understanding the default ringtone files provided by the Android system itself, which are placed in the/system/media/audio directory.

/system/media/audio/ringtones
System call Tones
/system/media/audio/notifications
System notification Ringtone
/system/media/audio/alarms
System Alarm Ringtones

The ringtones that you download can be placed in the music directory of the SD card. Mainly include: General ringtones (such as call tones), alarm tones and notification tones. These three types of ringtones are placed in the following directories:

/sdcard/music/ringtones   
User call ringtone
/sdcard/ Music/notifications 
user alert ringtone
/ SDCARD/MUSIC/ALARMS&NBSP
user alarm ringtone


Below is an example to learn how to set the system's default ringtone, alarm ringtone, notification ringtone


First write the interface file Layout_ring.xml

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"    android:layout_width= "Match_ Parent "    android:layout_height=" match_parent "    android:orientation=" vertical ">    <button        Android:id= "@+id/buttonringtone"        android:layout_width= "wrap_content"        android:layout_height= "Wrap_ Content "        android:text=" settings call ringtone "        />        <button        android:id=" @+id/buttonalarm "        android: Layout_width= "Wrap_content"        android:layout_height= "wrap_content"        android:text= "set alarm ringtone"        />            <button        android:id= "@+id/buttonnotification"        android:layout_width= "Wrap_content        " android:layout_height= "Wrap_content"        android:text= "set notification ringtone"        /></linearlayout>


Ringstonactivity.java File
Import Java.io.file;import android.app.activity;import Android.content.intent;import Android.media.RingtoneManager ; Import Android.net.uri;import Android.os.bundle;import android.view.view;import Android.view.View.OnClickListener ; Import android.widget.button;/** * Set the system's default ringtone, alarm ringtone, notification ringtone * <br/> blog address: <a href= "Blog.csdn.net/ouyang_peng" > Ouyangpeng csdn Blog </a> * @author Ouyangpeng * */public class Ringstonactivity extends Activity {/* 3 buttons */private button Mbutto Nringtone;private button mbuttonalarm;private button mbuttonnotification;/* custom type */public static final int Code_ Ringstone = 0;public static final int code_alarm = 1;public static final int code_notification = 2;/** * Incoming Ringtone folder */syst Em/media/audio/ringtones system Call Ringtone */sdcard/music/ringtones user call ringtone */private String strringtonefolder = "/system/m   Edia/audio/ringtones ";   Private String Strringtonefolder = "/sdcard/music/ringtones"; /** * Alarm Ringtone folder */system/media/audio/alarms system alarm ringtone */sdcard/music/alarms userAlarm clock ringtone */private String stralarmfolder = "/system/media/audio/alarms"; Private String Stralarmfolder = "/sdcard/music/alarms"; /** * Alarm Ringtone folder */system/media/audio/notifications system notification ringtone */sdcard/music/notifications user notification ringtone */private String s  Trnotificationfolder = "/system/media/audio/notifications";  Private String Strnotificationfolder = "/sdcard/music/notifications"; /** called when the activity is first created. */@Overridepublic void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( r.layout.layout_ring) Mbuttonringtone = (Button) Findviewbyid (r.id.buttonringtone); mbuttonalarm = (Button) Findviewbyid (r.id.buttonalarm); mbuttonnotification = (Button) Findviewbyid (r.id.buttonnotification); Mbuttonringtone.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View v) {if (Hasfolder ( Strringtonefolder) {//Open system ringtone settings Intent intent = new Intent (ringtonemanager.action_ringtone_picker);// Type is call Ringtoneintent.putextra (RingtonemanAger. Extra_ringtone_type,ringtonemanager.type_ringtone);//Set the displayed Titleintent.putextra (ringtonemanager.extra_ringtone_ TITLE, "Ouyangpeng set caller ringtone");//When Setup is complete, return to current activitystartactivityforresult (intent, Code_ringstone);}}); Mbuttonalarm.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View v) {if (Hasfolder ( Stralarmfolder) {//Open system ringtone settings Intent intent = new Intent (ringtonemanager.action_ringtone_picker);// Set the ringtone type and Titleintent.putextra (Ringtonemanager.extra_ringtone_type,ringtonemanager.type_alarm); Intent.putExtra ( Ringtonemanager.extra_ringtone_title, "Ouyangpeng set alarm ringtone"),//When Setup is complete, return to the current Activitystartactivityforresult (intent, Code_ ALARM);}}); Mbuttonnotification.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View v) {if (Hasfolder ( Strnotificationfolder) {//Open system ringtone settings Intent intent = new Intent (ringtonemanager.action_ringtone_picker);// Set the ringtone type and Titleintent.putextra (ringtonemanager.extra_ringtone_type,ringtonemanager.type_notification); Intent.putextra (Ringtonemanager.exTra_ringtone_title, "Ouyangpeng set notification ringtone");//When the setup is complete, return to the current Activitystartactivityforresult (intent, code_notification);}});} /** * callback function after setting ringtone */@Overrideprotected void onactivityresult (int requestcode, int resultcode, Intent data) {Super.onacti Vityresult (Requestcode, ResultCode, data); if (resultcode! = RESULT_OK) {return;} Get our choice of ringtone URI Pickeduri = Data.getparcelableextra (Ringtonemanager.extra_ringtone_picked_uri); if (Pickeduri! = null) {switch (requestcode) {case code_ringstone://sets the ringtone we select as the default call tone Ringtonemanager.setactualdefaultringtoneuri (this, Ringtonemanager.type_ringtone, Pickeduri); Break;case code_alarm:// Set the ringtone we choose to be the default alarm ringtone Ringtonemanager.setactualdefaultringtoneuri (this,ringtonemanager.type_alarm, Pickeduri); Case code_notification://Sets the ringtone we choose to be the default notification ringtone Ringtonemanager.setactualdefaultringtoneuri (this, Ringtonemanager.type_notification, Pickeduri); break;}}} /** * Detects if the specified folder exists, creates a * * @param strfolder * Folder path if it does not exist */private Boolean hasfolder (String strfolder) {Boolea N btmp= false; File F = new file (strfolder), if (!f.exists ()) {if (F.mkdirs ()) {btmp = true;} else {btmp = false;}} else {btmp = true;} return btmp;}}




here's how to run:



==================================================================================================

Ouyangpeng welcome reprint, sharing with people is the source of progress!

Reprint please keep the original address : Http://blog.csdn.net/ouyang_peng

==================================================================================================

  

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

My Android Advanced tour------>android system to set default call tones, alarm tones, notification ringtones

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.