FmRadioReceiver is a sample application that demonstrates the use of the
+android.fm.FmReceiver
+class to implement a FM Radio receiver in an application. The application allows the
+user to tune to any local radio stations, switch between them, scan for new stations and
+mute the radio. It also allows the user to change the radio band to their suit their location.
+The use of listeners is shown to display the tuned station name if RDS data is present.
+
+
The FmRadioReceiver.java file in FmRadioReceiver also illustrates the interaction with
+the MediaPlayer.
+
+
diff --git a/samples/FmRadioReceiver/res/drawable/backward.png b/samples/FmRadioReceiver/res/drawable/backward.png
new file mode 100755
index 000000000..c53408f3a
Binary files /dev/null and b/samples/FmRadioReceiver/res/drawable/backward.png differ
diff --git a/samples/FmRadioReceiver/res/drawable/backwardbutton.xml b/samples/FmRadioReceiver/res/drawable/backwardbutton.xml
new file mode 100755
index 000000000..22ff20159
--- /dev/null
+++ b/samples/FmRadioReceiver/res/drawable/backwardbutton.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/FmRadioReceiver/res/drawable/backwardpress.png b/samples/FmRadioReceiver/res/drawable/backwardpress.png
new file mode 100755
index 000000000..3fcfada18
Binary files /dev/null and b/samples/FmRadioReceiver/res/drawable/backwardpress.png differ
diff --git a/samples/FmRadioReceiver/res/drawable/forward.png b/samples/FmRadioReceiver/res/drawable/forward.png
new file mode 100755
index 000000000..a3f6a75f8
Binary files /dev/null and b/samples/FmRadioReceiver/res/drawable/forward.png differ
diff --git a/samples/FmRadioReceiver/res/drawable/forwardbutton.xml b/samples/FmRadioReceiver/res/drawable/forwardbutton.xml
new file mode 100755
index 000000000..bbefffc87
--- /dev/null
+++ b/samples/FmRadioReceiver/res/drawable/forwardbutton.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/FmRadioReceiver/res/drawable/forwardpress.png b/samples/FmRadioReceiver/res/drawable/forwardpress.png
new file mode 100755
index 000000000..417b99db6
Binary files /dev/null and b/samples/FmRadioReceiver/res/drawable/forwardpress.png differ
diff --git a/samples/FmRadioReceiver/res/drawable/icon.png b/samples/FmRadioReceiver/res/drawable/icon.png
new file mode 100755
index 000000000..a07c69fa5
Binary files /dev/null and b/samples/FmRadioReceiver/res/drawable/icon.png differ
diff --git a/samples/FmRadioReceiver/res/drawable/pause.png b/samples/FmRadioReceiver/res/drawable/pause.png
new file mode 100755
index 000000000..ff5ffd71f
Binary files /dev/null and b/samples/FmRadioReceiver/res/drawable/pause.png differ
diff --git a/samples/FmRadioReceiver/res/drawable/pausebutton.xml b/samples/FmRadioReceiver/res/drawable/pausebutton.xml
new file mode 100755
index 000000000..92b7c894e
--- /dev/null
+++ b/samples/FmRadioReceiver/res/drawable/pausebutton.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/FmRadioReceiver/res/drawable/pausepress.png b/samples/FmRadioReceiver/res/drawable/pausepress.png
new file mode 100755
index 000000000..e4d978ca0
Binary files /dev/null and b/samples/FmRadioReceiver/res/drawable/pausepress.png differ
diff --git a/samples/FmRadioReceiver/res/drawable/play.png b/samples/FmRadioReceiver/res/drawable/play.png
new file mode 100755
index 000000000..5b77d3b75
Binary files /dev/null and b/samples/FmRadioReceiver/res/drawable/play.png differ
diff --git a/samples/FmRadioReceiver/res/drawable/playbutton.xml b/samples/FmRadioReceiver/res/drawable/playbutton.xml
new file mode 100755
index 000000000..12ba91e13
--- /dev/null
+++ b/samples/FmRadioReceiver/res/drawable/playbutton.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/FmRadioReceiver/res/drawable/playpress.png b/samples/FmRadioReceiver/res/drawable/playpress.png
new file mode 100755
index 000000000..c0063c7c2
Binary files /dev/null and b/samples/FmRadioReceiver/res/drawable/playpress.png differ
diff --git a/samples/FmRadioReceiver/res/drawable/rescan.png b/samples/FmRadioReceiver/res/drawable/rescan.png
new file mode 100755
index 000000000..2d2cc2aa1
Binary files /dev/null and b/samples/FmRadioReceiver/res/drawable/rescan.png differ
diff --git a/samples/FmRadioReceiver/res/drawable/rescanbutton.xml b/samples/FmRadioReceiver/res/drawable/rescanbutton.xml
new file mode 100755
index 000000000..9585ff587
--- /dev/null
+++ b/samples/FmRadioReceiver/res/drawable/rescanbutton.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/FmRadioReceiver/res/drawable/rescanpress.png b/samples/FmRadioReceiver/res/drawable/rescanpress.png
new file mode 100755
index 000000000..a03ce7aaf
Binary files /dev/null and b/samples/FmRadioReceiver/res/drawable/rescanpress.png differ
diff --git a/samples/FmRadioReceiver/res/layout/main.xml b/samples/FmRadioReceiver/res/layout/main.xml
new file mode 100755
index 000000000..355823d1d
--- /dev/null
+++ b/samples/FmRadioReceiver/res/layout/main.xml
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/FmRadioReceiver/res/values/strings.xml b/samples/FmRadioReceiver/res/values/strings.xml
new file mode 100755
index 000000000..ec714c20e
--- /dev/null
+++ b/samples/FmRadioReceiver/res/values/strings.xml
@@ -0,0 +1,12 @@
+
+
+ FmRadioReceiver
+ Select Band
+ U.S
+ Europe
+ Japan
+ China
+ Select Station
+ FM RADIO
+ - - - -
+
diff --git a/samples/FmRadioReceiver/src/com/example/android/fmradioreceiver/FmRadioReceiver.java b/samples/FmRadioReceiver/src/com/example/android/fmradioreceiver/FmRadioReceiver.java
new file mode 100755
index 000000000..269dd84f6
--- /dev/null
+++ b/samples/FmRadioReceiver/src/com/example/android/fmradioreceiver/FmRadioReceiver.java
@@ -0,0 +1,518 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.fmradioreceiver;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.media.MediaPlayer;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.SubMenu;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.TextView;
+import android.widget.Toast;
+import com.stericsson.hardware.fm.FmBand;
+import com.stericsson.hardware.fm.FmReceiver;
+
+import java.io.IOException;
+
+
+public class FmRadioReceiver extends Activity {
+
+ // The string to find in android logs
+ private static final String LOG_TAG = "FM Radio Demo App";
+
+ // The string to show that the station list is empty
+ private static final String EMPTY_STATION_LIST = "No stations available";
+
+ // The 50kHz channel offset
+ private static final int CHANNEL_OFFSET_50KHZ = 50;
+
+ // The base menu identifier
+ private static final int BASE_OPTION_MENU = 0;
+
+ // The band menu identifier
+ private static final int BAND_SELECTION_MENU = 1;
+
+ // The station menu identifier
+ private static final int STATION_SELECTION_MENU = 2;
+
+ // Handle to the Media Player that plays the audio from the selected station
+ private MediaPlayer mMediaPlayer;
+
+ // The scan listener that receives the return values from the scans
+ private FmReceiver.OnScanListener mReceiverScanListener;
+
+ // The listener that receives the RDS data from the current channel
+ private FmReceiver.OnRDSDataFoundListener mReceiverRdsDataFoundListener;
+
+ // The started listener is activated when the radio has started
+ private FmReceiver.OnStartedListener mReceiverStartedListener;
+
+ // Displays the currently tuned frequency
+ private TextView mFrequencyTextView;
+
+ // Displays the current station name if there is adequate RDS data
+ private TextView mStationNameTextView;
+
+ // Handle to the FM radio Band object
+ private FmBand mFmBand;
+
+ // Handle to the FM radio receiver object
+ private FmReceiver mFmReceiver;
+
+ // Indicates if we are in the initialization sequence
+ private boolean mInit = true;
+
+ // Indicates that we are restarting the app
+ private boolean mRestart = false;
+
+ // Protects the MediaPlayer and FmReceiver against rapid muting causing
+ // errors
+ private boolean mPauseMutex = false;
+
+ // Array of the available stations in MHz
+ private ArrayAdapter mMenuAdapter;
+
+ // The name of the storage string
+ public static final String PREFS_NAME = "FMRadioPrefsFile";
+
+ // The menu items
+ public static final int FM_BAND = Menu.FIRST;
+
+ public static final int BAND_US = Menu.FIRST + 1;
+
+ public static final int BAND_EU = Menu.FIRST + 2;
+
+ public static final int BAND_JAPAN = Menu.FIRST + 3;
+
+ public static final int BAND_CHINA = Menu.FIRST + 4;
+
+ public static final int STATION_SELECT = Menu.FIRST + 5;
+
+ public static final int STATION_SELECT_MENU_ITEMS = STATION_SELECT + 1;
+
+ // The currently selected FM Radio band
+ private int mSelectedBand;
+
+ /**
+ * Required method from parent class
+ *
+ * @param icicle - The previous instance of this app
+ */
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ setContentView(R.layout.main);
+ mFmReceiver = (FmReceiver) getSystemService("fm_receiver");
+ SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
+ mSelectedBand = settings.getInt("selectedBand", 1);
+ mFmBand = new FmBand(mSelectedBand);
+ setupButtons();
+ }
+
+ /**
+ * Starts up the listeners and the FM radio if it isn't already active
+ */
+ @Override
+ protected void onStart() {
+ super.onStart();
+ mReceiverScanListener = new com.stericsson.hardware.fm.FmReceiver.OnScanListener() {
+
+ // FullScan results
+ public void onFullScan(int[] frequency, int[] signalStrength, boolean aborted) {
+ ((Button) findViewById(R.id.FullScan)).setEnabled(true);
+ showToast("Fullscan complete", Toast.LENGTH_LONG);
+ mMenuAdapter.clear();
+ if (frequency.length == 0) {
+ mMenuAdapter.add(EMPTY_STATION_LIST);
+ return;
+ }
+ for (int i = 0; i < frequency.length; i++) {
+ String a = Double.toString((double) frequency[i] / 1000);
+ if (mFmBand.getChannelOffset() == CHANNEL_OFFSET_50KHZ) {
+ a = String.format(a, "%.2f");
+ } else {
+ a = String.format(a, "%.1f");
+ }
+ mMenuAdapter.add(a);
+ }
+ if (mInit) {
+ mInit = false;
+ try {
+ mFmReceiver.setFrequency(frequency[0]);
+ mFrequencyTextView.setText(mMenuAdapter.getItem(0).toString());
+ } catch (IOException e) {
+ showToast("Unable to set the receiver's frequency", Toast.LENGTH_LONG);
+ } catch (IllegalArgumentException e) {
+ showToast("Unable to set the receiver's frequency", Toast.LENGTH_LONG);
+ }
+ }
+ }
+
+ // Returns the new frequency.
+ public void onScan(int tunedFrequency, int signalStrength, int scanDirection, boolean aborted) {
+ String a = Double.toString((double) tunedFrequency / 1000);
+ if (mFmBand.getChannelOffset() == CHANNEL_OFFSET_50KHZ) {
+ mFrequencyTextView.setText(String.format(a, "%.2f"));
+ } else {
+ mFrequencyTextView.setText(String.format(a, "%.1f"));
+ }
+ ((Button) findViewById(R.id.ScanUp)).setEnabled(true);
+ ((Button) findViewById(R.id.ScanDown)).setEnabled(true);
+ }
+ };
+ mReceiverRdsDataFoundListener = new com.stericsson.hardware.fm.FmReceiver.OnRDSDataFoundListener() {
+
+ // Receives the current frequency's RDS Data
+ public void onRDSDataFound(Bundle rdsData, int frequency) {
+ if (rdsData.containsKey("PSN")) {
+ mStationNameTextView.setText(rdsData.getString("PSN"));
+ }
+ }
+ };
+
+ mReceiverStartedListener = new com.stericsson.hardware.fm.FmReceiver.OnStartedListener() {
+
+ public void onStarted() {
+ // Activate all the buttons
+ ((Button) findViewById(R.id.ScanUp)).setEnabled(true);
+ ((Button) findViewById(R.id.ScanDown)).setEnabled(true);
+ ((Button) findViewById(R.id.Pause)).setEnabled(true);
+ ((Button) findViewById(R.id.FullScan)).setEnabled(true);
+ initialBandscan();
+ startAudio();
+ }
+ };
+
+ mFmReceiver.addOnScanListener(mReceiverScanListener);
+ mFmReceiver.addOnRDSDataFoundListener(mReceiverRdsDataFoundListener);
+ mFmReceiver.addOnStartedListener(mReceiverStartedListener);
+
+ if (!mRestart) {
+ turnRadioOn();
+ }
+ mRestart = false;
+ }
+
+ /**
+ * Stops the FM Radio listeners
+ */
+ @Override
+ protected void onRestart() {
+ super.onRestart();
+ mRestart = true;
+ }
+
+ /**
+ * Stops the FM Radio listeners
+ */
+ @Override
+ protected void onStop() {
+ super.onStop();
+
+ if (mFmReceiver != null) {
+ mFmReceiver.removeOnScanListener(mReceiverScanListener);
+ mFmReceiver.removeOnRDSDataFoundListener(mReceiverRdsDataFoundListener);
+ mFmReceiver.removeOnStartedListener(mReceiverStartedListener);
+ }
+ }
+
+ /**
+ * Saves the FmBand for next time the program is used and closes the radio
+ * and media player.
+ */
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
+ SharedPreferences.Editor editor = settings.edit();
+ editor.putInt("selectedBand", mSelectedBand);
+ editor.commit();
+ try {
+ mFmReceiver.reset();
+ } catch (IOException e) {
+ Log.e(LOG_TAG, "Unable to reset correctly", e);
+ }
+ if (mMediaPlayer != null) {
+ mMediaPlayer.release();
+ mMediaPlayer = null;
+ }
+ }
+
+ /**
+ * Starts the initial bandscan in it's own thread
+ */
+ private void initialBandscan() {
+ Thread bandscanThread = new Thread() {
+ public void run() {
+ try {
+ mFmReceiver.startFullScan();
+ } catch (IllegalStateException e) {
+ showToast("Unable to start the scan", Toast.LENGTH_LONG);
+ return;
+ }
+ }
+ };
+ bandscanThread.start();
+ }
+
+ /**
+ * Helper method to display toast
+ */
+ private void showToast(final String text, final int duration) {
+ runOnUiThread(new Runnable() {
+ public void run() {
+ Toast.makeText(getApplicationContext(), text, duration).show();
+ }
+ });
+ }
+
+ /**
+ * Starts the FM receiver and makes the buttons appear inactive
+ */
+ private void turnRadioOn() {
+
+ try {
+ mFmReceiver.startAsync(mFmBand);
+ // Darken the the buttons
+ ((Button) findViewById(R.id.ScanUp)).setEnabled(false);
+ ((Button) findViewById(R.id.ScanDown)).setEnabled(false);
+ ((Button) findViewById(R.id.Pause)).setEnabled(false);
+ ((Button) findViewById(R.id.FullScan)).setEnabled(false);
+ showToast("Scanning initial stations", Toast.LENGTH_LONG);
+ } catch (IOException e) {
+ showToast("Unable to start the radio receiver.", Toast.LENGTH_LONG);
+ } catch (IllegalStateException e) {
+ showToast("Unable to start the radio receiver.", Toast.LENGTH_LONG);
+ }
+ }
+
+ /**
+ * Starts the FM receiver and makes the buttons appear inactive
+ */
+ private void startAudio() {
+
+ mMediaPlayer = new MediaPlayer();
+ try {
+ mMediaPlayer.setDataSource("fmradio://rx");
+ mMediaPlayer.prepare();
+ mMediaPlayer.start();
+ } catch (IOException e) {
+ showToast("Unable to start the media player", Toast.LENGTH_LONG);
+ }
+ }
+
+ /**
+ * Sets up the buttons and their listeners
+ */
+ private void setupButtons() {
+
+ mMenuAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item);
+ mMenuAdapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
+ mMenuAdapter.add("No stations available");
+ mFrequencyTextView = (TextView) findViewById(R.id.FrequencyTextView);
+ mStationNameTextView = (TextView) findViewById(R.id.PSNTextView);
+
+ final Button scanUp = (Button) findViewById(R.id.ScanUp);
+ scanUp.setOnClickListener(new OnClickListener() {
+
+ public void onClick(View v) {
+ try {
+ mFmReceiver.scanUp();
+ } catch (IllegalStateException e) {
+ showToast("Unable to ScanUp", Toast.LENGTH_LONG);
+ return;
+ }
+ scanUp.setEnabled(false);
+ }
+ });
+ final Button scanDown = (Button) findViewById(R.id.ScanDown);
+ scanDown.setOnClickListener(new OnClickListener() {
+
+ public void onClick(View v) {
+ try {
+ mFmReceiver.scanDown();
+ } catch (IllegalStateException e) {
+ showToast("Unable to ScanDown", Toast.LENGTH_LONG);
+ return;
+ }
+ scanDown.setEnabled(false);
+ }
+ });
+ final Button pause = (Button) findViewById(R.id.Pause);
+ pause.setOnClickListener(new OnClickListener() {
+
+ public void onClick(View v) {
+ if (mFmReceiver.getState() == FmReceiver.STATE_PAUSED && mPauseMutex != true) {
+ try {
+ mPauseMutex = true;
+ mFmReceiver.resume();
+ mMediaPlayer.start();
+ pause.setBackgroundResource(R.drawable.pausebutton);
+ } catch (IOException e) {
+ showToast("Unable to resume", Toast.LENGTH_LONG);
+ } catch (IllegalStateException e) {
+ showToast("Unable to resume", Toast.LENGTH_LONG);
+ }
+ mPauseMutex = false;
+ } else if (mFmReceiver.getState() == FmReceiver.STATE_STARTED
+ && mPauseMutex != true) {
+ try {
+ mPauseMutex = true;
+ mMediaPlayer.pause();
+ mFmReceiver.pause();
+ pause.setBackgroundResource(R.drawable.playbutton);
+ } catch (IOException e) {
+ showToast("Unable to pause", Toast.LENGTH_LONG);
+ } catch (IllegalStateException e) {
+ showToast("Unable to pause", Toast.LENGTH_LONG);
+ }
+ mPauseMutex = false;
+ } else if (mPauseMutex) {
+ showToast("MediaPlayer busy. Please wait and try again.", Toast.LENGTH_LONG);
+ } else {
+ Log.i(LOG_TAG, "No action: incorrect state - " + mFmReceiver.getState());
+ }
+ }
+ });
+ final Button fullScan = (Button) findViewById(R.id.FullScan);
+ fullScan.setOnClickListener(new OnClickListener() {
+
+ public void onClick(View v) {
+ try {
+ fullScan.setEnabled(false);
+ showToast("Scanning for stations", Toast.LENGTH_LONG);
+ mFmReceiver.startFullScan();
+ } catch (IllegalStateException e) {
+ showToast("Unable to start the scan", Toast.LENGTH_LONG);
+ }
+ }
+ });
+ }
+
+ /**
+ * Sets up the options menu when the menu button is pushed, dynamic
+ * population of the station select menu
+ */
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ menu.clear();
+ boolean result = super.onCreateOptionsMenu(menu);
+ SubMenu subMenu = menu.addSubMenu(BASE_OPTION_MENU, FM_BAND, Menu.NONE,
+ R.string.band_select);
+ subMenu.setIcon(android.R.drawable.ic_menu_mapmode);
+ // Populate the band selection menu
+ subMenu.add(BAND_SELECTION_MENU, BAND_US, Menu.NONE, R.string.band_us);
+ subMenu.add(BAND_SELECTION_MENU, BAND_EU, Menu.NONE, R.string.band_eu);
+ subMenu.add(BAND_SELECTION_MENU, BAND_JAPAN, Menu.NONE, R.string.band_ja);
+ subMenu.add(BAND_SELECTION_MENU, BAND_CHINA, Menu.NONE, R.string.band_ch);
+ subMenu.setGroupCheckable(BAND_SELECTION_MENU, true, true);
+ subMenu.getItem(mSelectedBand).setChecked(true);
+
+ subMenu = menu.addSubMenu(BASE_OPTION_MENU, STATION_SELECT, Menu.NONE,
+ R.string.station_select);
+ subMenu.setIcon(android.R.drawable.ic_menu_agenda);
+
+ // Dynamically populate the station select menu each time the option
+ // button is pushed
+ if (mMenuAdapter.isEmpty()) {
+ subMenu.setGroupEnabled(STATION_SELECTION_MENU, false);
+ } else {
+ subMenu.setGroupEnabled(STATION_SELECTION_MENU, true);
+ for (int i = 0; i < mMenuAdapter.getCount(); i++) {
+ subMenu.add(STATION_SELECTION_MENU, STATION_SELECT_MENU_ITEMS + i, Menu.NONE,
+ mMenuAdapter.getItem(i));
+ }
+ subMenu.setGroupCheckable(STATION_SELECTION_MENU, true, true);
+ }
+ return result;
+ }
+
+ public int getSelectStationMenuItem(MenuItem item) {
+ return item.getItemId() - STATION_SELECT_MENU_ITEMS;
+ }
+
+ /**
+ * React to a selection in the option menu
+ */
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+
+ switch (item.getGroupId()) {
+ case BAND_SELECTION_MENU:
+ switch (item.getItemId()) {
+ case BAND_US:
+ mSelectedBand = FmBand.BAND_US;
+ item.setChecked(true);
+ break;
+ case BAND_EU:
+ mSelectedBand = FmBand.BAND_EU;
+ item.setChecked(true);
+ break;
+ case BAND_JAPAN:
+ mSelectedBand = FmBand.BAND_JAPAN;
+ item.setChecked(true);
+ break;
+ case BAND_CHINA:
+ mSelectedBand = FmBand.BAND_CHINA;
+ item.setChecked(true);
+ break;
+ default:
+ break;
+ }
+ mFmBand = new FmBand(mSelectedBand);
+ try {
+ mFmReceiver.reset();
+ } catch (IOException e) {
+ showToast("Unable to restart the FM Radio", Toast.LENGTH_LONG);
+ }
+ if (mMediaPlayer != null) {
+ mMediaPlayer.release();
+ mMediaPlayer = null;
+ }
+ turnRadioOn();
+ break;
+ case STATION_SELECTION_MENU:
+ try {
+ if (!mMenuAdapter.getItem(getSelectStationMenuItem(item)).toString().matches(
+ EMPTY_STATION_LIST)) {
+ mFmReceiver.setFrequency((int) (Double.valueOf(mMenuAdapter.getItem(
+ getSelectStationMenuItem(item)).toString()) * 1000));
+ mFrequencyTextView.setText(mMenuAdapter.getItem(
+ getSelectStationMenuItem(item)).toString());
+ }
+ } catch (IOException e) {
+ showToast("Unable to set the frequency", Toast.LENGTH_LONG);
+ } catch (IllegalStateException e) {
+ showToast("Unable to set the frequency", Toast.LENGTH_LONG);
+ } catch (IllegalArgumentException e) {
+ showToast("Unable to set the frequency", Toast.LENGTH_LONG);
+ }
+
+ break;
+ default:
+ break;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+}
diff --git a/samples/FmRadioTransmitter/Android.mk b/samples/FmRadioTransmitter/Android.mk
new file mode 100755
index 000000000..0c25b3525
--- /dev/null
+++ b/samples/FmRadioTransmitter/Android.mk
@@ -0,0 +1,12 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := samples
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+
+LOCAL_PACKAGE_NAME := FmRadioTransmitter
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_PACKAGE)
diff --git a/samples/FmRadioTransmitter/AndroidManifest.xml b/samples/FmRadioTransmitter/AndroidManifest.xml
new file mode 100755
index 000000000..ec0d33648
--- /dev/null
+++ b/samples/FmRadioTransmitter/AndroidManifest.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/FmRadioTransmitter/_index.html b/samples/FmRadioTransmitter/_index.html
new file mode 100755
index 000000000..0a286e206
--- /dev/null
+++ b/samples/FmRadioTransmitter/_index.html
@@ -0,0 +1,14 @@
+
FmRadioTransmitter is a sample application that demonstrates the use of the
+android.fm.FmTransmitter
+class to implement a FM Radio transmitter in an application. The application allows the
+user to scan the 88MHz-90MHz frequency region for the channel with the least signal
+interference. The application then transmits any audio using the FM Radio chip.
+
+
The suggested use is to start a long media file in the MediaPlayer application
+then turn on the FmRadioTransmitter sample application.