Android Question Android Auto Support

danoveb

Member
Licensed User
Longtime User
As the subject. Is it possible with B4A and if than how?
At least i want to send audio to Android Auto speakers and optionally use its microphone also.

https://play.google.com/store/apps/details?id=com.podkicker

This app sends its audio successfully to Android Auto and I don't think
it was developed to support it, so it must be someway to make it work
with standard API.

The podkicker app also work with the Head unit Emulator. The audio plays in my computer speaker.
http://android-developers.blogspot.se/2015/08/announcing-android-auto-desktop-head.html

I have also tried the SoundAbout app (Pro) but with no success....
https://play.google.com/store/apps/details?id=com.woodslink.android.wiredheadphoneroutingfix.pro

Regards
danoveb
 

danoveb

Member
Licensed User
Longtime User
Maybe only a Manifest issue than?! I found this:


<application>
...
<meta-data android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc"/>
...<application>

From this page:
http://developer.android.com/training/auto/audio/index.html

The first i assume should be like this:
AddApplicationText(<activity android:name="com.google.android.gms.car.application"/>)

But how do i translate the android:resource="@xml/automotive_app_desc"/> in B4A?
 
Upvote 0

danoveb

Member
Licensed User
Longtime User
I tried to to start another music app after connection to Android Auto, and than the sound from that app is in my Head Unit emulator too. So your right. But if I play a mp3 from my B4A app, the sound doesn't go anywhere. I'm using the MediaPlayer.

If i start to play a mp3 song from a player, and at the same time play a sound from my app, the sound from my app also goes through.

I also tried to ReInitialize (Release and Initialize) before play, but with no difference.
 
Upvote 0

danoveb

Member
Licensed User
Longtime User
Yes! I have used that code for a long time in my app in my old car that didn't have android auto. Works very good, interrupts the current audio as it is a phone call, and the audio goes out of my speaker with "phone" quality. Actually, my first plan with the new car was to have two phones connected, one only for google maps navigation in android auto, and the other phone like i had it in my old car. But that didn't work. When having a phone connected to android auto, volkswagen doesn't allow another phone to be connected to bluetooth at the same time. (Having 2 phones connected at the same time on bluetooth is a new feature of the MIB2 in the Volkswagen MQB platform)

Actually, after upgrading to Lollipop it stopped working, so after some reversed engineering I ended up with this:

r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
r.RunMethod("startBluetoothSco")
r.RunMethod2("setMode", 3, "java.lang.int")
r.RunMethod2("setSpeakerphoneOn", True, "java.lang.boolean")
For n = 1 To 2
Sleep(1000)
Next
r.RunMethod2("setBluetoothScoOn", True,"java.lang.boolean")

But, still not work when connected to Android Auto.....
(Of course have I tried totally without the code above also...)
 
Last edited:
Upvote 0

danoveb

Member
Licensed User
Longtime User
I have tested several other apps now, and it seems like it is only sound from B4A created app that doesn't go to the Android Auto Head Unit.
But common for all apps, is that the App must be started After the device is connected to the Head Unit, otherwise no sound at all.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4A doesn't do anything special. It just loads the audio file and plays it with MediaPlayer.

Try to use Phone.VOLUME_VOICE_CALL stream instead of the default stream:
B4X:
Dim mp As MediaPlayer
mp.Initialize
Dim r As Reflector
r.Target = mp
r.Target = r.GetField("mp")
Dim p As Phone
r.RunMethod2("setAudioStreamType", p.VOLUME_VOICE_CALL ,"java.lang.int")
 
Upvote 0

danoveb

Member
Licensed User
Longtime User
With your code above, the sounds goes to the earphone regardless if I'm connected to the Head Unit or not. I have tested with Tasker, and have the same problem. I've tried all the stream outputs, "Call", "system", "alarm" goes to the phonespeaker. "Ringer" and "Notification" goes nowhere.
 
Last edited:
Upvote 0

danoveb

Member
Licensed User
Longtime User
Well, seems that we are stuck here. If I understand you correct Erel, it should just work, but for me it doesn't. So is it the Mediaplayer that doesn't support Android Auto? Seems like that (see my previous post) because I didn't make it work with Tasker either. Although, I'm seem to be the anyone who has interest of getting this to work, so i assume that the issue has low priority.
 
Upvote 0
Top