This article describes the jump to the system ringtone selection interface, the ringtone in Android through Ringtonemanager Management, Ringtonemanager management call Ring (Type_ringtone), beep (type_notification), Alarm Clock Ringtones (type_alarm), Ringtonemanager commonly used methods include: 1.getRingtone ()//Get Ringtones 2.getDefaultUri ()// Gets the default ringtone for a ringtone type of 3.setActualDefaultRingtoneUri ()//set default ringtone to a ringtone type of 4.getActualDefaultRingtoneUri (); Get default ringtone
About ringtone Management, if you want to drill down, it needs to go to the framework to see, in the light of practical considerations, this time do not dig deep!!
Paste the code:
[Java]View PlainCopy
- <span style="FONT-SIZE:14PX;" >import android.app.Activity;
- Import Android.content.Context;
- Import android.content.Intent;
- Import Android.media.RingtoneManager;
- Import Android.net.Uri;
- Import Android.os.Bundle;
- Import Android.util.Log;
- Import Android.view.View;
- Import Android.widget.Button;
- Import Android.widget.Toast;
- Public class Mainactivity extends Activity {
- private Button btn1 = null;
- private static final int Ringtone = 0;
- private Context Mcontext;
- @Override
- public void OnCreate (Bundle savedinstancestate) {
- super.oncreate (savedinstancestate);
- Mcontext = this ;
- Setcontentview (R.layout.activity_main);
- BTN1 = (Button) This.findviewbyid (R.ID.BUTTON01);
- Btn1.setonclicklistener (new Button.onclicklistener () {
- public void OnClick (View arg0) {
- //TODO auto-generated method stub
- //Turn on system ringtone settings
- Intent Intent = new Intent (
- Ringtonemanager.action_ringtone_picker);
- //set type to call
- //Intent.putextra (Ringtonemanager.extra_ringtone_type,
- //Ringtonemanager.type_ringtone);
- The default ringtone option is not displayed in the//list and is displayed by default
- Intent.putextra (Ringtonemanager.extra_ringtone_show_default,
- false);
- The mute option is not displayed in the//list, which is displayed by default, if the default mute item is selected by the user,
- //The Extra_ringtone_picked_uri is null
- //Intent.putextra (Ringtonemanager.extra_ringtone_show_silent,false);
- Intent.putextra (RINGTONEMANAGER.EXTRA_RINGTONE_INCLUDE_DRM,
- true);
- //Set the title of the list dialog box, do not set, default display "Ringtone"
- Intent.putextra (Ringtonemanager.extra_ringtone_title, "set caller ringtone");
- Startactivityforresult (Intent, Ringtone);
- }
- });
- }
- /**
- * Callback function after setting the ringtone
- */
- @Override
- protected void Onactivityresult (int requestcode, int resultcode, Intent data) {
- Super.onactivityresult (Requestcode, ResultCode, data);
- if (resultcode! = RESULT_OK) {
- return;
- } Else {
- //Get our choice of ringtones, if you choose "Mute", then will return null
- URI uri = Data
- . Getparcelableextra (Ringtonemanager.extra_ringtone_picked_uri);
- LOG.E ("onactivityresult====", " " "+ uri);
- Toast.maketext (Mcontext, Uri + "", + ). Show ();
- if (uri! = null) {
- switch (requestcode) {
- Case Ringtone:
- Ringtonemanager.setactualdefaultringtoneuri (This,
- Ringtonemanager.type_ringtone, URI);
- Break ;
- }
- }
- }
- }
- }
- </span>
The code has comments, not too much nonsense!!
Put a picture on it:
Select the ringtone, click "OK" button, will immediately callback Onactivityresult () method, about the ringtone management aspects of the first here!!
Android Ringtonemanager Ringtones Management