Android FM module Learn one FM START process

Source: Internet
Author: User

Recently in the study of the FM module, FM is a learning module that can be seen from the upper layer. The upper layer is the FM's push-button operation and the interface display, which calls to the FM low-level driver to achieve the function of radio listening.

Look at the FM startup process:


First Enter the Fmradio.java class, OnCreate initialize some data, draw the FM interface, start the FM in the OnStart () method to start the Fmradioservice.java (call Bindtoservice (this, OSC) method).


Register under FM settings (send a set broadcast after Setup, update the status of the Fmradio Class).

Load initialization data, get frequency address

Newpresetstation ("", Fmsharedpreferences.gettunedfrequency ());


In the Bindtoservice (This,osc) method, start StartService (the same service only oncreate once), Restart Bindservice (this has the benefit of pressing the return key service does not go OnDestroy method) Bindservice Onbind back a IBinder object to Fmradio class Serviceconnection Onserviceco Nnected method, call the Enableradio () method.


Call Fmradio.java's Isantennaavailable () method in the Enableraido method to make a headset judgment, the antenna is judged whether it is available, Controlled by a plug-in pull-out broadcast receive (Registerheadsetlistener () method in Fmradio) action (Intent.action_headset_plug)

mheadsetplugged = (Intent.getintextra ("state", 0) = = 1); Equals 1 indicates the headset is available and equals 0 is available.

Call Fmradio Method Fmon (Mservice.fmon ())

Interface available Enableradioonoffui ()


private void Enableradio () {misscaning = false;      Misseeking = false;      Missearching = false;      Boolean bstatus = false;      if (Ishdmion ()) {ShowDialog (dialog_cmd_failed_hdmi_on); }else {<span style= "font-family:kaiti_gb2312;" > </span>if (mservice! = null) {try {if (false = = Mservice.isfmon ()) && IsA                    Ntennaavailable ()) {bstatus = Mservice.fmon ();                       if (bstatus) {Tuneradio (fmsharedpreferences.gettunedfrequency ());                    Enableradioonoffui ();                       }else {log.e (LogTag, "Mservice.fmon failed");                       mcommandfailed = Cmd_fmon;                          if (iscallactive ()) {Enableradioonoffui ();                       ShowDialog (dialog_cmd_failed_call_on);                       }else {showDialog (dialog_cmd_failed);              }      }}else {Enableradioonoffui ();             }}catch (RemoteException e) {e.printstacktrace (); }          }      }   }

Initialize the Fmreceiver reference mreceiver = Newfmreceiver (fmradio_device_fd_string, FmCallbacks) in the Fmradioservice.java Fmon () method;

Remove the setting properties of the saved region frequency

Fmconfig config =fmsharedpreferences.getfmconfiguration ();

Really accept FM sound in

Bstatus =mreceiver.enable (Fmsharedpreferences.getfmconfiguration ());

Isspeakerenabled () speaker available, user-set speaker

Set the ringtone path

Boolean state =mreceiver.setanalogmode (Analogmode); Analogmode Analog Set Low power

Bstatus = Setlowpowermode (false);

The phone is not in the idle form too

int state = Getcallstate ();

Fmactiononcallstate (state);


Activate FM STARTFM (), set headset, etc. to accept FM sound

Audiosystem.setforceuse (Audiosystem.for_media,audiosystem.force_none);

FM Device available

Audiosystem.setdeviceconnectionstate (AUDIOSYSTEM.DEVICE_OUT_FM,

Audiosystem.device_state_available, "");

Registering the processing of a remote group

Bstatus = mreceiver.registerrdsgroupprocessing (fmreceiver.fm_rx_rds_grp_rt_ebl|

fmreceiver.fm_rx_rds_grp_ps_ebl|

fmreceiver.fm_rx_rds_grp_af_ebl|

FMRECEIVER.FM_RX_RDS_GRP_PS_SIMPLE_EBL);

can automatically jump to the selected frequency

Bstatus =enableautoaf (Fmsharedpreferences.getautoafswitch ());

Set the built-in antenna to 0

Fmtransceiver.java
Fmreceiverjni.setcontrolnative (SFd, V4l2_cid_private_tavarua_antenna,iantenna)

Mreceiver.setinternalantenna (False)



Android FM module Learn one FM START process

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.