Tuesday, June 26, 2012

Re: [android-developers] Re: listenUsingInsecureRfcommWithServiceRecord

Hi

don't have an answer regarding the time period issue you have but wonder if you or anyone else has insight into my issue -


The problem is that the standard socket call for RFCOMM keeps failing with an error code of "1". Iti is as if the adapter is not initialized. Socket handle does not return a real handle and is < 1. If I change the socket call to any normal (non-bluetooth) call it works but can bind of course.

{
struct sockaddr_rc loc_addr = { 0 }, rem_addr = { 0 };
char buf[1024] = { 0 };
int s, client, bytes_read;
socklen_t opt = sizeof(rem_addr);

// allocate socket
s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);

// bind socket to port 1 of the first available
// local bluetooth adapter
loc_addr.rc_family = AF_BLUETOOTH;
loc_addr.rc_bdaddr = *BDADDR_ANY;
loc_addr.rc_channel = (uint8_t) 1;
bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr
*************************

The Java activity based code uses this to initialize the BT device through the adapter and enables it -

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
// Device does not support Bluetooth
}

if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult
(enableBtIntent, REQUEST_ENABLE_BT);
}

How can I do this in native code, since my java wrapper is just a call into this code base.

thanks,

/mpd


On Tue, Jun 26, 2012 at 7:25 PM, gjs <garyjamessilva@gmail.com> wrote:
Hi,

If you dig deeply I think you will find it was present in API's before
Level 10 but was only available unsupported/privately by using java
reflection.

See in here for an example
http://mobisocial.github.com/EasyNFC/apidocs/reference/mobisocial/nfc/addon/BluetoothConnector.OnConnectedListener-source.html

Regards

On Jun 27, 3:19 am, bob <b...@coolfone.comze.com> wrote:
> Can someone help me understand why this feature did not show up until API
> Level 10?
>
> public BluetoothServerSocket listenUsingInsecureRfcommWithServiceRecord
> (String name, UUID uuid)
>
> Is this making use of some new feature that is not widely supported?  I'm
> trying to program a desktop to talk to an Android device that's calling
> this function, and it's not going well.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment