Example usage for android.content Context RADIO_SERVICE

List of usage examples for android.content Context RADIO_SERVICE

Introduction

In this page you can find the example usage for android.content Context RADIO_SERVICE.

Prototype

String RADIO_SERVICE

To view the source code for android.content Context RADIO_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.hardware.radio.RadioManager for accessing the broadcast radio service.

Usage

From source file:com.google.android.car.kitchensink.radio.RadioTestFragment.java

private void initializeRadio() {
    mRadioManager = (RadioManager) getContext().getSystemService(Context.RADIO_SERVICE);

    if (mRadioManager == null) {
        throw new IllegalStateException("RadioManager could not be loaded.");
    }//w  w  w .  ja va2  s  .c  om

    int status = mRadioManager.listModules(mModules);
    if (status != RadioManager.STATUS_OK) {
        throw new IllegalStateException("Load modules failed with status: " + status);
    }

    if (mModules.size() == 0) {
        throw new IllegalStateException("No radio modules on device.");
    }

    boolean isDebugLoggable = Log.isLoggable(TAG, Log.DEBUG);

    // Load the possible radio bands. For now, just accept FM and AM bands.
    for (RadioManager.BandDescriptor band : mModules.get(0).getBands()) {
        if (isDebugLoggable) {
            Log.d(TAG, "loading band: " + band.toString());
        }

        if (mFmDescriptor == null && band.isFmBand()) {
            mFmDescriptor = (RadioManager.FmBandDescriptor) band;
        }

        if (mAmDescriptor == null && band.isAmBand()) {
            mAmDescriptor = (RadioManager.AmBandDescriptor) band;
        }
    }

    if (mFmDescriptor == null && mAmDescriptor == null) {
        throw new IllegalStateException("No AM and FM radio bands could be loaded.");
    }

    mFmConfig = new RadioManager.FmBandConfig.Builder(mFmDescriptor).setStereo(true).build();
    mAmConfig = new RadioManager.AmBandConfig.Builder(mAmDescriptor).setStereo(true).build();
}