bluetooth - How to create programmatically an A2DP connection or how can I emulate an Android phone to be an A2DP sink? -


i have 2 android phones (samsung galaxy tab , htc desire). both 2.2. galaxy tab should a2dp sink , desire source. aim route sound of desire galaxy. saw in api possible establish rfcomm connection. want establish a2dp connection. requirements solution none of phones should rooted.

i found in source code bluetooth uuid class. , tried open a2dp connection uuids.

this code of server side:

private class acceptthread extends thread {   public acceptthread() {        try {        bluetoothserversocket mmserversocket = btadapter.listenusingrfcommwithservicerecord("audio sink", uuid.fromstring("0000110b-0000-1000-8000-00805f9b34fb")); // uuid of audio sink        mmserversocket = btadapter.listenusingrfcommwithservicerecord(     "avcrp controller", uuid.fromstring("0000110e-0000-1000-8000-00805f9b34fb")); // uuid of avcrp controller                      } catch (ioexception e) {     } }     public void run() { // keep listening until exception occurs or socket returned while (true) { try {          socket = mmserversocket.accept();  } catch (ioexception e) {     break; } // if connection accepted if (socket != null) {     try {     mmserversocket.close(); } catch (ioexception e) {     e.printstacktrace();     } 

code of client side:

method m = device.getclass().getmethod("createrfcommsocket", new class[] { int.class }); tmp = (bluetoothsocket) m.invoke(device, integer.valueof(1)); 

i pair both devices , create connection. if go bluetooth settings of desire , long press on galaxy tab, have menu options. can see media profile. if tried check connection box connect device selected profiles following log:

04-11 17:21:18.994: debug/dtun_hcid4(1233):         dtun_client_get_remote_services() 04-11 17:21:18.994: info/dtun_hcid4(1233): dtun_client_get_remote_services: remote services on  04-11 17:21:18.994: info/dtun_clnt(1233):     client calling dtun_method_dm_get_remote_services (id 5) 04-11 17:21:18.994: info/(1220): dtun_receivectrlmsg: [dtun] received message [btlif_dtun_method_call] 4354 04-11 17:21:18.994: info/(1220): handle_method_call: handle_method_call :: received dtun_method_dm_get_remote_services (id 5), len 6 04-11 17:21:18.994: error/btld(1220): ****************search uuid = 1108*********** 04-11 17:21:18.994: warn/btld(1220): ccb timer ticks: 0 04-11 17:21:19.005: info//system/bin/btld(1219):         btapp_dm_getremoteservices() 04-11 17:21:19.005: info//system/bin/btld(1219): ##### userial_ioctl: bt_wake, 0x8003 #### 04-11 17:21:19.125: warn/btld(1220): process_service_search_attr_rsp 04-11 17:21:19.144: warn/btld(1220): ccb timer ticks: 0 04-11 17:21:19.155: error/btld(1220): ****************search uuid = 111e*********** 04-11 17:21:19.155: warn/btld(1220): ccb timer ticks: 0 04-11 17:21:19.287: warn/btld(1220): process_service_search_attr_rsp 04-11 17:21:19.287: warn/btld(1220): ccb timer ticks: 0 04-11 17:21:19.336: error/btld(1220): ****************search uuid = 110b*********** 04-11 17:21:19.336: warn/btld(1220): ccb timer ticks: 0 04-11 17:21:19.474: warn/btld(1220): process_service_search_attr_rsp 04-11 17:21:19.474: warn/btld(1220): ccb timer ticks: 0 04-11 17:21:19.534: info/btl-ifs(1220): send_ctrl_msg: [btl_ifs ctrl] send btlif_dtun_signal_evt (ctrl) 14 pbytes (hdl 15) 04-11 17:21:19.534: info/dtun_hcid4(1233): dtun_dm_sig_rmt_services: success=1, service=00040040 04-11 17:21:19.534: debug/dtun_hcid4(1233): adding uuid 0000111e-0000-1000-8000-00805f9b34fb 04-11 17:21:19.534: debug/device(1233): add profiles /org/bluez/1233/hci0/dev_xx_xx_xx_xx_xx_xx 04-11 17:21:19.534: info/dtun_hcid4(1233): adding uuid 0000111e-0000-1000-8000-00805f9b34fb 04-11 17:21:19.534: debug/dtun_hcid4(1233): adding uuid 0000110b-0000-1000-8000-00805f9b34fb 04-11 17:21:19.534: debug/device(1233): add profiles /org/bluez/1233/hci0/dev_xx_xx_xx_x_xx_xx 04-11 17:21:19.534: info/dtun_hcid4(1233): adding uuid 0000110b-0000-1000-8000-00805f9b34fb 04-11 17:21:19.534: info/dtun_hcid4(1233): calling sink_init 04-11 17:21:19.534: debug/adapter(1233): adapter_get_device(xx:xx:xx:xx:xx:xx) 04-11 17:21:19.534: debug/device(1233): btd_device_ref(0xfa10): ref=2 04-11 17:21:19.534: info/dtun_hcid4(1233): sink_init 04-11 17:21:19.534: debug/dtun_hcid4(1233): registered interface org.bluez.audiosink on path /org/bluez/1233/hci0/dev_xx_xx_xx_xx_xx_xx 04-11 17:21:19.544: error/bluetootheventloop.cpp(96): event_filter: received signal org.bluez.device:propertychanged /org/bluez/1233/hci0/dev_xx_xx_xx_xx_xx_xx 04-11 17:21:19.544: debug/bluetoothservice(96): updatedeviceservicechannelcache(xx:xx:xx:xx:xx:xx) 04-11 17:21:19.554: info/device(1233): pattern = 0000111e-0000-1000-8000-00805f9b34fb, id = 4 04-11 17:21:19.564: debug/bluetoothservice(96):     uuid(system): 0000111e-0000-1000-8000-00805f9b34fb 4382 04-11 17:21:19.574: verbose/bluetootheventredirector(492): received android.bleutooth.device.action.uuid 04-11 17:21:19.700: warn/btld(1220): ccb timer ticks: 0 04-11 17:21:20.615: info//system/bin/btld(1219): ##### userial_ioctl: bt_sleep, 0x8004 #### 04-11 17:21:24.634: debug/dalvikvm(594): gc_explicit freed 46 objects / 2320 bytes in 50ms 04-11 17:21:24.675: info/system.out(1336): public android.bluetooth.bluetootha2dp(android.content.context) 04-11 17:21:24.684: debug/bluetootha2dpservice(96): connectsink(xx:xx:xx:xx:xx:xx) 04-11 17:21:24.684: info/bluetootha2dpservice(96): checksinksuspendstate() : state = 1 prevstate = 0 04-11 17:21:24.684: info/bluetootha2dpservice(96): checksinksuspendstate() : mtargeta2dpstate = -1 04-11 17:21:24.684: info/bluetootha2dpservice(96): checksinksuspendstate() : initialstart = false initialsuspend = false 04-11 17:21:24.694: verbose/bluetootheventredirector(492): received android.bluetooth.a2dp.action.sink_state_changed 04-11 17:21:24.694: debug/cachedbluetoothdevice(492): onprofilestatechanged:[] 04-11 17:21:24.705: debug/bluetootha2dpservice(96): a2dp state : device: bc:47:60:0f:4b:f3 state:0->1 04-11 17:21:24.705: info/dtun_clnt(1233):     client calling dtun_method_am_av_open (id 20) 04-11 17:21:24.705: info/(1220): dtun_receivectrlmsg: [dtun] received message [btlif_dtun_method_call] 4354 04-11 17:21:24.705: info/(1220): handle_method_call: handle_method_call :: received dtun_method_am_av_open (id 20), len 6 04-11 17:21:24.705: error/btld(1220): reset flags 04-11 17:21:24.705: warn/btld(1220): ccb timer ticks: 0 04-11 17:21:24.705: debug/dtun_hcid4(1233): stream creation in progress 04-11 17:21:24.714: info//system/bin/btld(1219): ##### userial_ioctl: bt_wake, 0x8003 #### 04-11 17:21:24.958: warn/btld(1220): process_service_search_attr_rsp 04-11 17:21:25.017: warn/btld(1220): ccb timer ticks: 0 04-11 17:21:25.227: error/btld(1220): bta_av_rc_create acp handle exist shdl:0 04-11 17:21:25.325: warn/btld(1220): bta_dm_rm_cback:0, status:1 04-11 17:21:25.325: warn/btld(1220): bta_dm_act no entry connected service cbs 04-11 17:21:25.325: info/btl-ifs(1220): send_ctrl_msg: [btl_ifs ctrl] send btlif_dtun_signal_evt (ctrl) 44 pbytes (hdl 15) 04-11 17:21:25.325: warn/btld(1220): btui_av_callback(bta_av_open_evt::failed (page-timeout or protocol)::status: 3 04-11 17:21:25.325: info/dtun_hcid4(1233): pending 04-11 17:21:25.325: info/dtun_hcid4(1233): orig_msg = e588 04-11 17:21:25.325: error/bluetootha2dpservice.cpp(96): onconnectsinkresult: d-bus error: org.bluez.error.failed (stream connection failed) 04-11 17:21:25.325: info/bluetootha2dpservice(96): checksinksuspendstate() : state = 0 prevstate = 1 04-11 17:21:25.325: info/bluetootha2dpservice(96): checksinksuspendstate() : mtargeta2dpstate = -1 04-11 17:21:25.325: info/bluetootha2dpservice(96): checksinksuspendstate() : initialstart = false initialsuspend = false 04-11 17:21:25.334: verbose/bluetootheventredirector(492): received android.bluetooth.a2dp.action.sink_state_changed 04-11 17:21:25.334: info/bluetootheventredirector(492): failed connect bt a2dp 04-11 17:21:25.334: debug/cachedbluetoothdevice(492): onprofilestatechanged:[] 04-11 17:21:25.334: debug/bluetootha2dpservice(96): a2dp state : device: bc:47:60:0f:4b:f3 state:1->0 04-11 17:21:25.925: info//system/bin/btld(1219): ##### userial_ioctl: bt_sleep, 0x8004 #### 04-11 17:21:26.775: warn/btld(1220): ccb timer ticks: 2147483648 04-11 17:21:26.785: info//system/bin/btld(1219): ##### userial_ioctl: bt_wake, 0x8003 #### 04-11 17:21:27.725: info//system/bin/btld(1219): ##### userial_ioctl: bt_sleep, 0x8004 #### 

does know doing wrong? general question possible connect 2 android phones via bluetooth , stream 1 phone other? have alternative approaches?

thanks

you cannot on rfcomm / spp - connecting a2dp uuid not enough - profile connection / profile level protocol procedures need done implement a2dp - more on a2dp directly works on l2cap protocol (and not require rfcomm).

you may-not able manually between 2 phones because stream 1 device needs a2dp sink , other other a2dp source, phones typically source devices (source of stream can stream sink devices) , sinks headsets or bluetooth speakers.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -