ringtonemanager-getting the system's current ringtone

Source: Internet
Author: User

We look directly at the code

BT1 =(Button) Findviewbyid (R.ID.BT1); BT2=(Button) Findviewbyid (R.ID.BT2); BT3=(Button) Findviewbyid (R.ID.BT3); Bt2.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View arg0) {//get a phone beep                if(Mnotificationuri_notify = =NULL) {mnotificationuri_notify=Ringtonemanager. Getactualdefaultringtoneuri (mainactivity. This, ringtonemanager.type_notification); }                if(Mnotificationuri_notify! =NULL&& Mringtone_notify = =NULL) {string string=mnotificationuri_notify.tostring ();                    Tv.settext (string); Mringtone_notify=Ringtonemanager.getringtone (Getapplicationcontext (), mnotificationuri_notify); }                if(Mringtone_notify! =NULL) {                    if(Mringtone_notify.isplaying ()) {mringtone_notify.stop (); } Else{mringtone_notify. Setstreamtype (Audiomanager.stream_notificat                        ION);                    Mringtone_notify.play ();        }                }            }        }); Bt1.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View arg0) {//Get phone call tones                if(Mnotificationuri_telephone = =NULL) {Mnotificationuri_telephone=Ringtonemanager. Getactualdefaultringtoneuri (mainactivity. This, Ringtonemanager.type_ringtone); }                if(Mnotificationuri_telephone! =NULL&& Mringtone_telephone = =NULL) {Mringtone_telephone=Ringtonemanager. Getringtone (Getapplicationcontext (), M                Notificationuri_telephone); }                if(Mringtone_telephone! =NULL) {                    if(Mringtone_telephone.isplaying ()) {mringtone_telephone.stop (); } Else{mringtone_telephone. Setstreamtype (audiomanager.stream_ring);                    Mringtone_telephone.play ();        }                }            }        }); Bt3.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View arg0) {if(Mnotificationuri_alarm = =NULL) {                    //get phone alarm ringtonesMnotificationuri_alarm =Ringtonemanager. Getactualdefaultringtoneuri (mainactivity. This, Ringtonemanager.type_alarm); }                if(Mnotificationuri_alarm! =NULL&& Mringtone_alarm = =NULL) {Mringtone_alarm=Ringtonemanager.getringtone (Getapplicationcontext (), mnotificationuri_alarm); }                if(Mringtone_alarm! =NULL) {                    if(Mringtone_alarm.isplaying ()) {mringtone_alarm.stop (); } Else{mringtone_alarm. Setstreamtype (Audiomanager.stream_alarm);                    Mringtone_alarm.play (); }                }            }        });

The code above is the code to get three ringtones for your phone.

In fact, the operation of getting ringtones is also very simple.

It mainly involves two classes of

1.ringtonemanager-Ringtone Management class

2.ringtone-Ringtones Operation class

It's basically a three-step process.

1. Get the URI

To get the URI method, you need to pass in a parameter ringtonemanager.type_notification (stream_notification). ) is

This parameter determines what kind of tone we get.

2. Get ringtone

The way to get it requires the first step to get the URI to come in, you can get the corresponding ringtone

3. Operation Ringtones

Only play () stop () is used to control the stop and play of the ringtone directly.

There is a method above

Mringtone_alarm.setstreamtype (Audiomanager.stream_alarm);

Say is set audio stream, this audio stream is what thing, also do not understand, saw someone said

in the audio subsystem of the Android Framework, each audio stream corresponds to an instance of a Audiotrack class, and each audiotrack is registered to Audioflinger when it is created. All audiotrack are mixed (Mixer) by Audioflinger and then transported to the audiohardware for playback. Audiotrack and Audioflinger communication mechanisms Typically, audiotrack and Audioflinger are not in the same process, and they connect through the binder mechanism in Android.

I checked the information, the feeling should be to control what audio parsing it

ringtonemanager-getting the system's current ringtone

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.