Created
August 10, 2020 07:36
-
-
Save SergeyBurlaka/f29eff69f4a455343ebf729fab22d9ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); | |
brr(new BroadcastReceiver() { | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, -1); | |
Log.d(TAG, "Audio SCO state: " + state); | |
if (AudioManager.SCO_AUDIO_STATE_CONNECTED == state) { | |
/* | |
* Now the connection has been established to the bluetooth device. | |
* Record audio or whatever (on another thread).With AudioRecord you can record with an object created like this: | |
* new AudioRecord(MediaRecorder.AudioSource.MIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO, | |
* AudioFormat.ENCODING_PCM_16BIT, audioBufferSize); | |
* | |
* After finishing, don't forget to unregister this receiver and | |
* to stop the bluetooth connection with am.stopBluetoothSco(); | |
*/ | |
unregisterReceiver(this); | |
} | |
} | |
}, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED)); | |
Log.d(TAG, "starting bluetooth"); | |
am.startBluetoothSco(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment