Example usage for android.hardware.radio RadioManager STATUS_OK

List of usage examples for android.hardware.radio RadioManager STATUS_OK

Introduction

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

Prototype

int STATUS_OK

To view the source code for android.hardware.radio RadioManager STATUS_OK.

Click Source Link

Document

Method return status: successful operation

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  ww  w.  ja v a 2 s .  co 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();
}