views:

352

answers:

1

Hi,

I’m currently working on a Android project and is very newbie to the Android platform. It’s an exercise I got from an article where I have to create a twitterlike application so that one Android platform can write to another and it automatically is updating. I’m using a Bluetooth emulator for Android to test.

But before I start with that I’ve facing some difficulties with the initiating a Bluetooth connection and have tried out several tutorials inclusive the official Android API / samples.

I got a class called “BlueTweetService” and within this I got three methods: configureBluetoothServerSocket, connectToServerDevice and shutdownBluetoothServerSocket.

In the first method, configureBluetoothServerSocket, I’ve to open a BluetoothServerSocket and using the properties String BluetoothTweetName and UUID BlueTweetUuid.

I’ve tried to create / open the serversocket but I gives me errors no matter what I do.

I would really appreciate if someone could help me with the code how to create / open that serversocket.

If I need to provide some information, please let me know and I’ll post them.

Sincerely Mestika

+1  A: 

If you want to create a BluetoothServerSocket do this

BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
BluetoothServerSocket tmp_ss = null;
try {
    tmp_ss = adapter.listenUsingRfcommWithServiceRecord(BluetoothTweetName , BlueTweetUuid);
} catch (IOException e) {
    e.printStackTrace();
}

When you create such a socket it will wait for incoming connection. You could not use it for send or receive messages.

hara