Android Ringtonemanager Ringtones Management

Source: Internet
Author: User

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
  1. <span style="FONT-SIZE:14PX;"  >import android.app.Activity;
  2. Import Android.content.Context;
  3. Import android.content.Intent;
  4. Import Android.media.RingtoneManager;
  5. Import Android.net.Uri;
  6. Import Android.os.Bundle;
  7. Import Android.util.Log;
  8. Import Android.view.View;
  9. Import Android.widget.Button;
  10. Import Android.widget.Toast;
  11. Public class Mainactivity extends Activity {
  12. private Button btn1 = null;
  13. private static final int Ringtone = 0;
  14. private Context Mcontext;
  15. @Override
  16. public void OnCreate (Bundle savedinstancestate) {
  17. super.oncreate (savedinstancestate);
  18. Mcontext = this ;
  19. Setcontentview (R.layout.activity_main);
  20. BTN1 = (Button) This.findviewbyid (R.ID.BUTTON01);
  21. Btn1.setonclicklistener (new Button.onclicklistener () {
  22. public void OnClick (View arg0) {
  23. //TODO auto-generated method stub
  24. //Turn on system ringtone settings
  25. Intent Intent = new Intent (
  26. Ringtonemanager.action_ringtone_picker);
  27. //set type to call
  28. //Intent.putextra (Ringtonemanager.extra_ringtone_type,
  29. //Ringtonemanager.type_ringtone);
  30. The default ringtone option is not displayed in the//list and is displayed by default
  31. Intent.putextra (Ringtonemanager.extra_ringtone_show_default,
  32. false);
  33. The mute option is not displayed in the//list, which is displayed by default, if the default mute item is selected by the user,
  34. //The Extra_ringtone_picked_uri is null
  35. //Intent.putextra (Ringtonemanager.extra_ringtone_show_silent,false);
  36. Intent.putextra (RINGTONEMANAGER.EXTRA_RINGTONE_INCLUDE_DRM,
  37. true);
  38. //Set the title of the list dialog box, do not set, default display "Ringtone"
  39. Intent.putextra (Ringtonemanager.extra_ringtone_title, "set caller ringtone");
  40. Startactivityforresult (Intent, Ringtone);
  41. }
  42. });
  43. }
  44. /** 
  45. * Callback function after setting the ringtone
  46. */
  47. @Override
  48. protected void Onactivityresult (int requestcode, int resultcode, Intent data) {
  49. Super.onactivityresult (Requestcode, ResultCode, data);
  50. if (resultcode! = RESULT_OK) {
  51. return;
  52. } Else {
  53. //Get our choice of ringtones, if you choose "Mute", then will return null
  54. URI uri = Data
  55. . Getparcelableextra (Ringtonemanager.extra_ringtone_picked_uri);
  56. LOG.E ("onactivityresult====", " " "+ uri);
  57. Toast.maketext (Mcontext, Uri + "", + ). Show ();
  58. if (uri! = null) {
  59. switch (requestcode) {
  60. Case Ringtone:
  61. Ringtonemanager.setactualdefaultringtoneuri (This,
  62. Ringtonemanager.type_ringtone, URI);
  63. Break ;
  64. }
  65. }
  66. }
  67. }
  68. }
  69. </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

Related Article

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.