Next, take a look at Android\vendor\qcom\opensource\fm\fmapp2\src\com\caf\fmradio\fmtags.java.
When you click the All channels option in the Fmradio.java menu, jump to the Fmtags.java class
Defines a ListView control and a simple adapter
Private ListView LA;
Private arrayadapter<string> adapter;
Refresh the UI interface with handler
Private final Handler Mhandler = Newhandler ();
Use iterators private Iterator ITR;
Iterate over the Fmsharedpreferences class and use the loop to add to the character array, using the adapter display.
final Runnable mdisplaytaglist = new Runnable () {public void run () { String[] tags; int l = 0; tags = new string[fmsharedpreferences.num_tags]; for (int i = 0; i < fmsharedpreferences.max_num_tag_types; i++) {if (fmsharedpreferences.taglist[ I] = null) {ITR = Fmsharedpreferences.taglist[i].iterator (); while (Itr.hasnext ()) tags[l++] = ((Fmsharedpreferences.tag_names[i]) + "\ n" + "\ T" + (String) itr.next ()); }} adapter = new Arrayadapter (La.getcontext (), Android. R.layout.simple_list_item_1, tags); La.setadapter (adapter); } };
Re-analyze the class of an FM headset key Android\vendor\qcom\opensource\fm\fmapp2\src\com\caf\fmradio\fmmediabuttonintentreceiver.java
Phone headset controls volume or other, receives action via static registration ("Android.intent.action.MEDIA_BUTTON")
Key to listen for events
KeyEvent event = (keyevent) Intent.getparcelableextra (intent.extra_key_event);
Monitor whether the headset is headphones and tap down to listen
Intkeycode = Event.getkeycode ();
Intkey_action = Event.getaction ();
Send an accompanying intent.extra_key_event broadcast to fmradioservice implement some functions to achieve the answer.
Keyevent.keycode_headsethook: Whether the monitor is a headset
Keyevent.action_down: Whether the monitor presses the key
Keyevent.keycode_media_play_pause: Pause
Keyevent.keycode_media_play Play key
Keyevent.keycode_media_next: Short press = play next music, long press = current music Fast Forward
Keyevent.keycode_media_previous: Short press = Play previous music, long press = current Music rewind
Standard headphones to test for monitoring events
public class Fmmediabuttonintentreceiver extends Broadcastreceiver {private static final String TAG = "Fmmediabuttoninten Treceiver ";p ublic static final String Fm_media_button =" Com.caf.fmradio.action.MEDIA_BUTTON ";p ublic static final String Audio_becoming_noisy = "Com.caf.fmradio.action.AUDIO_BECOMING_NOISY";p ublic void OnReceive (context context, Intent Intent) {String action = intent.getaction (); if (action = null) && action.equals (Audiomanager.action_audio_becoming_noisy)) {LOG.D (TAG, "Action_au Dio_becoming_noisy intent received for Action_headset_plug "); Intent i = new Intent (Audio_becoming_noisy); Context.sendbroadcast (i); } else if ((action = null) && action.equals ("Android.intent.action.MEDIA_BUTTON")) {KeyEvent event = ( KeyEvent) Intent.getparcelableextra (intent.extra_key_event); if (event = = null) {return; } int keycode = Event.getkeycode (); int key_action = Event.getaction (); if ((Keyevent.keycode_headsethook = = keycode) && (key_action = = keyevent.action_down)) | | (Keyevent.keycode_media_pause = = KeyCode) | | (Keyevent.keycode_media_play = = keycode)) {LOG.D (TAG, "Action_media_button intent received for Action_down"); Intent i = new Intent (Fm_media_button); I.putextra (Intent.extra_key_event, EVENT); Context.sendbroadcast (i); } } }
ANDROIDFM Module Learning Four source parsing (11)