I have an issue related to the headset mic in my android app.
This headset is working absolutely fine with all other apps on this device, but I can’t get audio from it my app. Also this app works fine with headsets on other devices.
Can’t reproduce with other headsets and devices. Same time other wireless headset works fine with my app
Android 12
Device Samsung A12
SDK 31
I use code below
val playbackAttributes = AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION)
.setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
.build()
val audioFocusRequest = AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT)
.setAudioAttributes(playbackAttributes)
.setAcceptsDelayedFocusGain(true)
.setOnAudioFocusChangeListener { }
.build()
audioManager.requestAudioFocus(audioFocusRequest)
val wired = audioManager.availableCommunicationDevices.firstOrNull { it.type == TYPE_WIRED_HEADSET }
audioManager.mode = AudioManager.MODE_IN_COMMUNICATION
audioManager.setCommunicationDevice(currentDevice)
Related
I am using google Audio Playback Capture API in ANDROID API Level 29 and its working fine on Android mobile devices i get easily internal audio from the devices but when i test it on the Android TV Box , Basically this app is TV box app where i have to capture internal audio. My Android TV Box connected with HDMI cable but i didn't receive any sound i am using Attributes : USAGE_MEDIA,USAGE_UNKNOWN and USAGE_GAME
they are all working fine in mobile app but not when i run on Android Box. I have done everything from my side now i just need help regarding getting audio from HDMI.
Thanks
val config = AudioPlaybackCaptureConfiguration.Builder(AudioCaptureService.mediaProjection!!)
.addMatchingUsage(AudioAttributes.USAGE_MEDIA)
.addMatchingUsage(AudioAttributes.USAGE_UNKNOWN)
.addMatchingUsage(AudioAttributes.USAGE_GAME)
.build()
val audioFormat = AudioFormat.Builder()
.setEncoding(AudioFormat.ENCODING_PCM_16BIT)
.setSampleRate(buffer.sampleRate)
.setChannelMask(AudioFormat.CHANNEL_IN_MONO)
.build()
val record = AudioRecord.Builder()
.setAudioFormat(audioFormat)
.setAudioPlaybackCaptureConfig(config)
.setBufferSizeInBytes(buffer.size)
.build()
I'm developing an App using BLE and I need to be able to connect to Android and iOS devices.
I have 3 Samsung Devices, 3 iPhones and one Huawei with Android for testing purposes.
I have an issue with the Huawei device..when scanning for advertisements, Huawei finds all Android devices but no iOS ones. But if I turn bluetooth off and on again, it will find the iOS devices this time if I scan. But only the first time, it won't find them again afterwards until I turn bluetooth off/on again.
Again..only the Huawei is having these issues..what can be the cause?
I scan/advertise like this:
val settings = AdvertiseSettings.Builder()
.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED)
.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM)
.setConnectable(true)
.build()
val pUuid = ParcelUuid(UUID.fromString(BluetoothStringsValues.SERVICE_UUID))
val data = AdvertiseData.Builder()
.setIncludeDeviceName(false)
.addServiceUuid(pUuid)
.addServiceData(pUuid, stringToAdvertise.toByteArray(Charset.forName("UTF-8")))
.build()
advertiser.startAdvertising(settings, data, advertisingCallback)
val filter = ScanFilter.Builder()
.setServiceUuid(ParcelUuid(UUID.fromString(SERVICE_UUID)))
.build()
val settings = ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_BALANCED)
.build()
bluetoothLeScanner.startScan(listOf(filter), settings, bleScanCallback)
thanks for the help!
I am developing a solution to check BLE devices and I used the native API that comes with Android to check BluetoothLeScanner.
Wanted to understand a little better operation, I take the location permission and bluetooth.
After the scan starts, I turn Bluetooth on my phone to off, on Moto G2 Android 6.0 Scan still keeps giving me the expected result when I test on a Samsung S8 Android 9 and Sony Xperia T2 Ultra Android 5.1 in the log I get which was bluetooth disabled and the scan was stopped.
I can only perform the test when I purchase it as follows
bluetoothManager = getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
bluetoothAdapter = bluetoothManager.adapter
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
bluetoothScanner = bluetoothAdapter.bluetoothLeScanner
}
#TargetApi(Build.VERSION_CODES.M)
class BleScanCallback(resultMap: MutableMap) : ScanCallback() {
var resultOfScan = resultMap
#RequiresApi(Build.VERSION_CODES.LOLLIPOP)
#TargetApi(Build.VERSION_CODES.M)
override fun onScanResult(callbackType: Int, result: ScanResult?) {
addScanResult(result)
Log.v("Main Activity", "I found a ble device ${result}")
Log.v("Main Activity", "I found a ble device ${result?.device?.address}")
}
override fun onBatchScanResults(results: MutableList<ScanResult>?) {
results?.forEach { result -> addScanResult(result) }
}
override fun onScanFailed(errorCode: Int) {
Log.v("Main Activity","Bluetooth LE scan failed. Error code: $errorCode")
}
fun addScanResult(scanResult: ScanResult?) {
val bleDevice = scanResult?.device
val deviceAddress = bleDevice?.address
resultOfScan.put(deviceAddress, bleDevice)
}
scanResult is bringing the necessary information when bluetooth is online, I already set it up as the image below
https://i.stack.imgur.com/o9jGRm.png
I see that this makes scanning even off
On some Android devices including Pixel phones, Android One devices, and unmodified AOSP builds, turning off bluetooth in the quick settings panel doesn't really turn off bluetooth. Instead, it merely blocks bluetooth connections and pairing in software, yet allows Bluetooth LE scans to continue unaffected. As #Jorgesys correctly notes, it is impossible to detect BLE devices if the Bluetooth radio is really turned off, so let me say again: despite what the quick settings panel says, bluetooth is not necessarily powered off.
On supported devices, this happens only if two things are true:
Bluetooth is turned on in the full settings menu (On Android 9: Settings -> Connected Devices -> Connection preferences -> Bluetooth ON)
The user has selected to "Allow apps and services to scan for nearby devices at any time, even when Bluetooth is off. This can be used, for example, to improve location-based features and services." (Settings -> Security & Location -> Location -> Advanced -> Scanning -> Bluetooth scanning ON)
There is no way to detect BLE devices with bluetooth off
Bluetooth must be enabled
Set up BLE
Before your application can communicate over BLE, you need
to verify that BLE is supported on the device, and if so, ensure that
it is enabled.
I have a small app which just performs a BLE Advertising.
The app runs on a Nexus 5x with Android 8.0
This is the code to start BLE advertising:
private fun startAdvertising() {
val serviceUuid = ParcelUuid.fromString("DAB5D1DC-0000-1000-8000-00805F9B34FB")
val data = AdvertiseData.Builder()
.setIncludeTxPowerLevel(false)
.setIncludeDeviceName(false)
.addServiceUuid(serviceUuid)
.build()
val settings = AdvertiseSettings.Builder()
.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY)
.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH)
.setConnectable(true)
.build()
bluetoothLeAdvertiser!!.startAdvertising(settings, data, advertiserCallback)
}
The advertising starts, but the payload is wrong. On Pre-Android 8.0 devices we receive the correct service-uuid when scan for this messages with a 2nd device:
32-bit Service-UUID: 0xDAB5D1DC
But when I start the advertisements on my Nexus 5x with Android 8.0, I receive an incorrect service-uuid:
32-bit Service-UUID: 0x0000D1DC
For the BLE scanning part I use the nrf Connect app from playstore.
Everything works as expected, if I advertise a common 128-bit Service UUID and not an 32-bit one.
Are there any changes for Android 8.0 regarding my issue?
Update 2017-08-28:
Same issue on a Nexus 6P. Created an issue: https://issuetracker.google.com/issues/65099899
Use only ParcelUuid.fromString("DAB5D1DC")
this will make youre packet smaller.
youre problem is probably because youre advertise packet too big i think the max is 32 bytes.
Create Constants
public static final UUID serviceUuid = UUID.fromString("DAB5D1DC-0000-1000-8000-00805F9B34FB");
and than
val data = AdvertiseData.Builder()
.setIncludeTxPowerLevel(false)
.setIncludeDeviceName(true)
.addServiceUuid(new ParcelUuid(Constants.serviceUuid))
.build()
I'm working on an app to stream audio from shoutcast. The streaming goes well on my computer and when debugging it with an Android-configuration.
But when I deploy it to an APK-file and run it on a Samsung Galaxy S, the streaming doesn't work.
My code for streaming the audio:
var urlRequest:URLRequest = new URLRequest("http://.../;");
var soundContext:SoundLoaderContext = new SoundLoaderContext(2000, true);
soundChannel = new SoundChannel();
sound = new Sound(urlRequest, soundContext);
soundChannel = sound.play();
I've also tried an addEventListener(Event.COMPLETE), it seems my app doesn't get there when running on a Samsung Galaxy.
Pls check internet enabled descripted files.
http://help.adobe.com/en_US/air/build/WSfffb011ac560372f-5d0f4f25128cc9cd0cb-7ffc.html
Reffer Also
http://cookbooks.adobe.com/post_Playing_mp3_files_on_Flex_Mobile-19106.html