Android ringtone Analysis

Source: Internet
Author: User
Tags call back

Source code:

Frameworks/base/Media/Java/Android/Media/ringtonemanager. Java

Frameworks/base/Media/Java/Android/Media/ringtone. Java

Frameworks/base/CORE/Java/Android/preference/ringtonepreference. Java

Packages/providers/mediaprovider/src/COM/Android/providers/Media/ringtonepickeractivity. Java

Packages/apps/settings/src/COM/Android/settings/defaultringtonepreference. Java

(The Code is based on Qualcomm msm8625 4.1.2)

General Introduction: ringtonemanager manages all ringtones and provides external interfaces for third parties to read and set ringtones. ringtone is basically a ringtone object, it stores the basic information of the ringtone and some basic operations. ringtonepreference is the base class of the ringtone. ringtonepickactivity is the interface for selecting the ringtone we see. defaultringtonepreference is based on
Ringtonepreference, and rewrite some important methods in ringtonepreference.

Ringtonemanager. Java analysis:

Important methods:
Setactualdefaultringtoneuri (context, int type, Uri ringtoneuri); Set system ringtone

Getactualdefaultringtoneuri (context, int type); get system ringtone

There are some important methods, but most of them are private. If you are interested, you can study them yourself.

Ringtone. java analysis: the modified class encapsulates the URI, title, type, and other information of the ringtone, implements a mediaplayer in the class, and encapsulates the playing and stopping ringtones.

Ringtonepreference. java analysis: this class is the base class of ringtones. During the initialization of this class, the default ringtone type is read from the system, and whether the default ringtone and mute are displayed (as described below ); at the same time, this class implements onclick, onprepareringtonepickerintent, onactivityresult, and other methods, but these methods can only process system ringtones. When you set ringtones through the music player, problems will occur.

Ringotonepickeractivity. java analysis: this class is the activity used for selecting ringtones. However, in the Code provided by Qualcomm, the activity is indeed made into a dialog form (Android: theme = "@ * Android: style/theme. holo. dialog. alert ")

Defaultringtonepreference. java analysis: defaultringtonepreference inherits from ringtonepreference and implements onclick, onprepareringtonepickerintent, and onactivityresult. In this way, you can rewrite the parent class to set the system or external TKA ringtones as system ringtones.

Onactivityresult method source code: (this method is to achieve a variety of ringtone selection through a new method)

@ Override

Public Boolean onactivityresult (INT requestcode, int resultcode, intent data ){

Switch (mselecteditem ){

Case select_system:

Resetselection ();

Return super. onactivityresult (requestcode, resultcode, data );

Case select_external:

Resetselection ();

If (Data! = NULL ){

Uri uri = data. getdata ();

If (callchangelistener (Uri! = NULL? Uri. tostring ():"")){

Onsaveringtone (URI );

}

Return true;

}

}

Return false;

}

Set the ringtone process:

The following describes how to set a ringtone in settings-sound as an example:

1. First, the system is loaded to soundsettings and then determines whether it is a dual-card or

2. Single-card dual-card: COM. Android. settings. multisimsettings. multisimsettingtab

Single Card: COM. Android. settings. defaultringtonepreference

3. defaultrintonepreference. onclick () displays available applications (system ringtones, external storage ringtones)

4. In the displayed dialog box, select an application and click

Mselecteditem = which;

Defaultringtonepreference. Super. onclick ();

The following two lines of code are displayed, so that you can see the application you clicked on.

5. When

When you click the system ringtone, the system will go through ringtonepickactivity.

Click the external storage ringtone to send android. intent. action. ringtone_picker, usually musicpicker. java processing (packages/apps/music/src/COM/Android/music/musicpicker. java)

6. When you click OK to set the ringtone, the system will call back the defaultringtonepreference. onactivityresult method. When

When using an external application, ringtonemanager. setactualdefaultringtoneuri (getcontext (), getringtonetype (), ringtoneuri)

Super. onactivityresult (requestcode, resultcode, data)

TIPS:

<1> you can add the default ringtone and mute options on the ringtone selection page provided by Qualcomm.

Frameworks/base/CORE/RES/values/styles. xml

<Item name = "Android: showdefault"> true </item>

<Item name = "Android: showsilent"> true </item>

The two items above can control the display of the default ringtone and mute.

<2> default ringtone Configuration

Build/target/product/full_base.mk

Product_property_overrides + = \

Ro.config.ringtone1_ring_synth_04.ogg \

Ro.config.icationication_sound?pixiedust.ogg

After the system is started, these values are loaded into the database. If these values are configured in the system, the system will automatically find these values.

It is displayed as the default value. If it is not found, the system selects the first option on the page as the default value.

<3> add and delete a ringtone

The system ringtones are in the frameworks/base/data/sounds directory.

1. Add a ringtone: copy the ringtone to be added to this directory (you 'd better create a new directory), change the MK file (the file is under the root directory of sounds), and add

Add the ringtone to the MK file (for example, $ (local_path)/effects/unlock.ogg: System/Media/Audio/UI/lock.ogg \)

2. delete a ringtone: deleting a ringtone does not really allow you to delete a ringtone file. You only need to delete the compiled code in the MK file.

3. Compilation problem: when you want to delete a ringtone, we recommend that you first clear the system/Media/audio directory; otherwise, the deleted ringtone may be compiled.

The above content is personal understanding. If you have any mistakes, please correct them.

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.