Example usage for android.bluetooth.le AdvertiseCallback ADVERTISE_FAILED_ALREADY_STARTED

List of usage examples for android.bluetooth.le AdvertiseCallback ADVERTISE_FAILED_ALREADY_STARTED

Introduction

In this page you can find the example usage for android.bluetooth.le AdvertiseCallback ADVERTISE_FAILED_ALREADY_STARTED.

Prototype

int ADVERTISE_FAILED_ALREADY_STARTED

To view the source code for android.bluetooth.le AdvertiseCallback ADVERTISE_FAILED_ALREADY_STARTED.

Click Source Link

Document

Failed to start advertising as the advertising is already started.

Usage

From source file:com.android.bleserver.AdvertiserFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    advertisingFailureReceiver = new BroadcastReceiver() {

        /**//from  w  ww. j  a v a2s . c  o m
         * Receives Advertising error codes from {@code AdvertiserService} and displays error messages
         * to the user. Sets the advertising toggle to 'false.'
         */
        @Override
        public void onReceive(Context context, Intent intent) {

            int errorCode = intent.getIntExtra(AdvertiserService.ADVERTISING_FAILED_EXTRA_CODE, -1);

            mSwitch.setChecked(false);

            String errorMessage = getString(R.string.start_error_prefix);
            switch (errorCode) {
            case AdvertiseCallback.ADVERTISE_FAILED_ALREADY_STARTED:
                errorMessage += " " + getString(R.string.start_error_already_started);
                break;
            case AdvertiseCallback.ADVERTISE_FAILED_DATA_TOO_LARGE:
                errorMessage += " " + getString(R.string.start_error_too_large);
                break;
            case AdvertiseCallback.ADVERTISE_FAILED_FEATURE_UNSUPPORTED:
                errorMessage += " " + getString(R.string.start_error_unsupported);
                break;
            case AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR:
                errorMessage += " " + getString(R.string.start_error_internal);
                break;
            case AdvertiseCallback.ADVERTISE_FAILED_TOO_MANY_ADVERTISERS:
                errorMessage += " " + getString(R.string.start_error_too_many);
                break;
            case AdvertiserService.ADVERTISING_TIMED_OUT:
                errorMessage = " " + getString(R.string.advertising_timedout);
                break;
            default:
                errorMessage += " " + getString(R.string.start_error_unknown);
            }

            Toast.makeText(getActivity(), errorMessage, Toast.LENGTH_LONG).show();
        }
    };
}

From source file:sample.hawk.com.mybasicappcomponents.hardware.bt_advertisements.BLE_AdvertiserFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    advertisingFailureReceiver = new BroadcastReceiver() {

        /**//from w  w w  .j av  a 2 s . c o m
         * Receives Advertising error codes from {@code AdvertiserService} and displays error messages
         * to the user. Sets the advertising toggle to 'false.'
         */
        @Override
        public void onReceive(Context context, Intent intent) {

            int errorCode = intent.getIntExtra(BLE_AdvertiserService.ADVERTISING_FAILED_EXTRA_CODE, -1);

            mSwitch.setChecked(false);

            String errorMessage = getString(R.string.start_error_prefix);
            switch (errorCode) {
            case AdvertiseCallback.ADVERTISE_FAILED_ALREADY_STARTED:
                errorMessage += " " + getString(R.string.start_error_already_started);
                break;
            case AdvertiseCallback.ADVERTISE_FAILED_DATA_TOO_LARGE:
                errorMessage += " " + getString(R.string.start_error_too_large);
                break;
            case AdvertiseCallback.ADVERTISE_FAILED_FEATURE_UNSUPPORTED:
                errorMessage += " " + getString(R.string.start_error_unsupported);
                break;
            case AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR:
                errorMessage += " " + getString(R.string.start_error_internal);
                break;
            case AdvertiseCallback.ADVERTISE_FAILED_TOO_MANY_ADVERTISERS:
                errorMessage += " " + getString(R.string.start_error_too_many);
                break;
            case BLE_AdvertiserService.ADVERTISING_TIMED_OUT:
                errorMessage = " " + getString(R.string.advertising_timedout);
                break;
            default:
                errorMessage += " " + getString(R.string.start_error_unknown);
            }

            Toast.makeText(getActivity(), errorMessage, Toast.LENGTH_LONG).show();
        }
    };
}