Development

 

This chapter explains how to develop an FM radio application using the LG FMRadio SDK with source code.

Overview

You can implement LG FM radio in your application using the APIs provided with the LG FMRadio SDK.

You can control the operation of features such as FM Radio On/Off, Tune, Scan and Seek in your application using the LG FMRadio class APIs. Events and data relating to the operations launched by calling LG FMRadio APIs are received through an interface called ILGFmradioCallback. Your application checks the results of LG FMRadio API operations by implementing the ILGFmradioCallback.

Preparation

You can implement LG FM radio in your application using the APIs provided with the LG FMRadio SDK.

Creating an Android Project

Create a new module in Android Studio to start developing an FM radio application.

 

To develop applications run on N OS, you need to download Android Studio 2.1.2 and higher.

 

1. In Android Studio, create a new project from the File > New Project menu.

 

2. Under "Configure your new project," configure the fields as shown below and click Next button.

  • Application name
  • Company domain

fmradio_develop_1.png

 

3. Under "Select the form factors your app will run on," check the box for Phone and Tablet. For Minimum SDK, select API 23: Android 6.0. Then, click Next button.

fmradio_develop_2.png

 

4. Under "Add an activity to Mobile," select Blank Activity and click Next button.

 

5. Under "Customize the Activity," leave fields as default and click Finish button. Now your Android project is created.

 

Importing a Library

Once you have created an Android Project, you will import the LG FMRadio library.

 

1. Copy the library file from the libs folder of the SDK root path to the libs folder under app in your project.
    e.g.) workspace/MyFMRadioApp/app/libs

 

2. From the File menu, select New module.

 

3. Under “Create New Module”, choose ‘Phone and Tablet Application’ and ‘Import JAR or .AAR package’, then click Next button.

fmradio_develop_3.png

 

4. For the File name field, browse the project folder and find the LG FMRadio library, then click Finish button.

fmradio_develop_4.png

 

5. You will now see that the LG FMRadio module is added to the project.

 

6. Select Synchronize from the File menu. The LG FMRadio library is configured and ready to use.

 

7. If you develop applications runs on Android N OS, add the codes marked with bold font in your build configuration file, build.gradle. If you develop applications runs on Android M OS, you can skip this.

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.0"

    defaultConfig {
        applicationId "fmradio.lge.com.lgfmradioapp"
        minSdkVersion 23
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

        jackOptions {
            enabled true
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

Key Implementation

Modifying the AndroidManifest.xml File

The following permissions must be declared in your project’s AndroidManifest file to implement the LG FMRadio application.

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.ACCESS_FM_RECEIVER" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

 

Implementing the Class

Turning On/Off the FM Radio
RadioOn() or RadioOff() is called to tuning on/off the FM radio.

public boolean RadioOn( )
public boolean RadioOff( )


Searching for the Previous or Next Frequency

SeekForward() or SeekBackward() is called to search for the closest available frequency that comes after/before the current frequency.

public boolean SeekForward( )
public boolean SeekBackward( )


Changing the Channel to the Specified Frequency

tune() is called to change the channel to a specified frequency.

public boolean tune (int freq)

 

Starting/Terminating Scanning

scan() is called to search for all frequencies that can be listened to on FM radio or to stop searching for the frequencies.

public boolean scan( )
public boolean stopScanning( )

 

Turning On/Off the RDS

RdsOn() or RdsOff() is called to turn on/off the FM radio RDS feature.

public boolean RdsOn( )
public boolean RdsOff( )

 

Setting the Audio Mode

setAudioMode() is called to change audio mode while you are listening to FM radio. You can change audio mode to one of the following: Earphone Mode, Speaker Mode or Mute.

public void setAudioMode (AudioMode mode)
public enum AudioMode {
        AUDIO_MODE_EARPHONE, AUDIO_MODE_SPEAKER, AUDIO_MODE_MUTE
}

 

Getting the RSSI Value

getCurrentRssi() is called to get the RSSI value of the current FM channel.

public int getCurrentRssi( )

 

Implementing Callback Interface

Events and data relating to the operations launched by calling LG FMRadio APIs are received through an interface called ILGFmradioCallback, so you must implement the ILGFmradioCallback method in your application. Please refer to the API reference for detailed information on each method.

public static interface ILGFmradioCallback {
        void onRadioOnOffNotify(boolean b, boolean b1);
        void onTuneNotify(boolean b, int i);
        void onSeekNotify(boolean b, int i);
        void onScanNotify(boolean b, boolean b1, int i);
        void onRdsNotify(boolean b, boolean b1);
        void onRdsProgramServiceReceived(java.lang.String s);
        void onRdsRadioTextReceived(java.lang.String s, java.lang.String s1);
        void onRdsProgramIdentiReceived(java.lang.String s);
}

 

 

 

 

Navigation