Example usage for android.hardware.radio RadioManager.BandDescriptor toString

List of usage examples for android.hardware.radio RadioManager.BandDescriptor toString

Introduction

In this page you can find the example usage for android.hardware.radio RadioManager.BandDescriptor toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

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.");
    }/*from w w w  . j a v a2  s  .c o m*/

    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();
}