Example usage for android.media AudioManager ACTION_SCO_AUDIO_STATE_CHANGED

List of usage examples for android.media AudioManager ACTION_SCO_AUDIO_STATE_CHANGED

Introduction

In this page you can find the example usage for android.media AudioManager ACTION_SCO_AUDIO_STATE_CHANGED.

Prototype

String ACTION_SCO_AUDIO_STATE_CHANGED

To view the source code for android.media AudioManager ACTION_SCO_AUDIO_STATE_CHANGED.

Click Source Link

Document

Sticky broadcast intent action indicating that the Bluetooth SCO audio connection state has changed.

Usage

From source file:Main.java

public static String getScoUpdateAction() {
    if (Build.VERSION.SDK_INT >= 14) {
        return AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED;
    } else {//w ww  . j  a  v  a2s.co  m
        return AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED;
    }
}

From source file:com.morlunk.mumbleclient.channel.ChannelListFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    registerForContextMenu(mChannelView);
    getActivity().registerReceiver(mBluetoothReceiver,
            new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED));
}

From source file:com.jtxdriggers.android.ventriloid.VentriloidService.java

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.FROYO)//  www  .ja v  a  2s  .c o  m
public void toggleBluetooth() {
    recorder.stop();
    setXmit(false);
    sendBroadcast(new Intent(Connected.SERVICE_RECEIVER).putExtra("type", (short) -1));

    if (am.isBluetoothScoOn()) {
        player.setBlock(true);
        player.clear();
        recorder.stop();
        am.stopBluetoothSco();
        items.setBluetooth(false);
        player.setBlock(false);
    } else {
        player.setBlock(true);
        bluetoothConnected = false;
        items.setBluetoothConnecting("Connecting...");
        sendBroadcast(new Intent(Connected.SERVICE_RECEIVER));
        am.startBluetoothSco();
        registerReceiver(bluetoothReceiver, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED));
        handler.post(new Runnable() {
            int counter = 0;
            String text = "Connecting.";

            @Override
            public void run() {
                if (!bluetoothConnected) {
                    if (counter <= 10) {
                        if (text.equals("Connecting..."))
                            text = "Connecting.";
                        else
                            text += ".";
                        items.setBluetoothConnecting(text);
                        sendBroadcast(new Intent(Connected.SERVICE_RECEIVER));

                        counter++;

                        if (!bluetoothConnected)
                            handler.postDelayed(this, 1000);
                    } else {
                        am.stopBluetoothSco();
                        items.setBluetooth(false);
                        player.setBlock(false);
                        sendBroadcast(new Intent(Connected.SERVICE_RECEIVER));
                        Toast.makeText(VentriloidService.this, "Bluetooth request timed out.",
                                Toast.LENGTH_SHORT).show();
                        try {
                            unregisterReceiver(bluetoothReceiver);
                        } catch (IllegalArgumentException e) {
                        }
                    }
                }
            }
        });
    }
}