zrobiłem takie coś
class SerwerBluetooth extends Thread
{
private static final String TAG = "ServerThread";
private final BluetoothServerSocket mmServerSocket;
public SerwerBluetooth()
{
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
BluetoothServerSocket tmp = null;
try
{
UUID uuid=UUID.fromString("550e8400-e29b-41d4-a716-446655440000");
tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord("Usł‚uga witająca", uuid);
}
catch (IOException e)
{
Log.e(TAG, "initialization: " + e.getMessage());
}
mmServerSocket = tmp;
}
public void run()
{
Log.d("INFO","Uruchamiam serwer");
BluetoothSocket socket = null;
while (true)
{
try
{
Log.d("INFO","Czekam na połączenie od clienta");
socket = mmServerSocket.accept();
Log.d("INFO","Mam clienta!");
//PrintWriter out = new PrintWriter(socket.getOutputStream(),true);
//out.println("Witaj kolego!");
// BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
} catch (IOException e)
{
Log.e(TAG, "Server loop: " + e.getMessage());
break;
}
if (socket != null)
{
try
{
mmServerSocket.close();
} catch (Exception e)
{
e.printStackTrace();
}
break;
}
}
}
}
mam log taki
05-20 09:10:44.565 11104-11109/com.bluetooth2.app I/jdwp﹕ Ignoring second debugger -- accepting and dropping
05-20 09:10:44.595 11104-11109/com.bluetooth2.app I/jdwp﹕ Ignoring second debugger -- accepting and dropping
05-20 09:10:44.700 11104-11104/com.bluetooth2.app D/dalvikvm﹕ GC_FOR_ALLOC freed 91K, 13% free 9528K/10951K, paused 22ms, total 22ms
05-20 09:10:44.710 11104-11104/com.bluetooth2.app D/AbsListView﹕ Get MotionRecognitionManager
05-20 09:10:44.730 11104-11104/com.bluetooth2.app V/BluetoothSocket.cpp﹕ initSocketNative
05-20 09:10:44.740 11104-11104/com.bluetooth2.app V/BluetoothSocket.cpp﹕ ...fd 43 created (RFCOMM, lm = 26)
05-20 09:10:44.740 11104-11104/com.bluetooth2.app V/BluetoothSocket.cpp﹕ initSocketFromFdNative
05-20 09:10:44.745 11104-11104/com.bluetooth2.app D/BluetoothUtils﹕ isSocketAllowedBySecurityPolicy start : device null
05-20 09:10:44.745 11104-11104/com.bluetooth2.app V/BluetoothSocket.cpp﹕ bindListenNative
05-20 09:10:44.745 11104-11104/com.bluetooth2.app V/BluetoothSocket.cpp﹕ ...bindListenNative(43) success
05-20 09:10:44.745 11104-11104/com.bluetooth2.app V/BluetoothSocket.cpp﹕ abortNative
05-20 09:10:44.745 11104-11104/com.bluetooth2.app V/BluetoothSocket.cpp﹕ ...asocket_abort(43) complete
05-20 09:10:44.745 11104-11104/com.bluetooth2.app V/BluetoothSocket.cpp﹕ destroyNative
05-20 09:10:44.745 11104-11104/com.bluetooth2.app V/BluetoothSocket.cpp﹕ ...asocket_destroy(43) complete
05-20 09:10:44.745 11104-11104/com.bluetooth2.app E/ServerThread﹕ initialization: Not able to register SDP record for Usł‚uga witająca
05-20 09:10:44.750 11104-11104/com.bluetooth2.app V/BluetoothSocket.cpp﹕ initSocketNative
05-20 09:10:44.750 11104-11104/com.bluetooth2.app V/BluetoothSocket.cpp﹕ ...fd 43 created (RFCOMM, lm = 26)
05-20 09:10:44.750 11104-11104/com.bluetooth2.app V/BluetoothSocket.cpp﹕ initSocketFromFdNative
05-20 09:10:44.750 11104-11104/com.bluetooth2.app D/BluetoothUtils﹕ isSocketAllowedBySecurityPolicy start : device null
05-20 09:10:44.755 11104-11104/com.bluetooth2.app V/BluetoothSocket.cpp﹕ bindListenNative
05-20 09:10:44.755 11104-11104/com.bluetooth2.app V/BluetoothSocket.cpp﹕ ...bindListenNative(43) success
05-20 09:10:44.755 11104-11104/com.bluetooth2.app V/BluetoothSocket.cpp﹕ abortNative
05-20 09:10:44.755 11104-11104/com.bluetooth2.app V/BluetoothSocket.cpp﹕ ...asocket_abort(43) complete
05-20 09:10:44.755 11104-11104/com.bluetooth2.app V/BluetoothSocket.cpp﹕ destroyNative
05-20 09:10:44.755 11104-11104/com.bluetooth2.app V/BluetoothSocket.cpp﹕ ...asocket_destroy(43) complete
05-20 09:10:44.755 11104-11104/com.bluetooth2.app E/ServerThread﹕ initialization: Not able to register SDP record for Usł‚uga witająca
05-20 09:10:44.780 11104-11118/com.bluetooth2.app D/INFO﹕ Uruchamiam serwer
05-20 09:10:44.780 11104-11118/com.bluetooth2.app D/INFO﹕ Czekam na połączenie od clienta
05-20 09:10:44.780 11104-11118/com.bluetooth2.app W/dalvikvm﹕ threadid=11: thread exiting with uncaught exception (group=0x40df12a0)
05-20 09:11:05.295 11550-11550/com.bluetooth2.app D/dalvikvm﹕ GC_FOR_ALLOC freed 126K, 13% free 9528K/10951K, paused 17ms, total 18ms
05-20 09:11:05.315 11550-11550/com.bluetooth2.app D/AbsListView﹕ Get MotionRecognitionManager
05-20 09:11:05.330 11550-11550/com.bluetooth2.app V/BluetoothSocket.cpp﹕ initSocketNative
05-20 09:11:05.330 11550-11550/com.bluetooth2.app V/BluetoothSocket.cpp﹕ ...fd 43 created (RFCOMM, lm = 26)
05-20 09:11:05.330 11550-11550/com.bluetooth2.app V/BluetoothSocket.cpp﹕ initSocketFromFdNative
05-20 09:11:05.335 11550-11550/com.bluetooth2.app D/BluetoothUtils﹕ isSocketAllowedBySecurityPolicy start : device null
05-20 09:11:05.340 11550-11550/com.bluetooth2.app V/BluetoothSocket.cpp﹕ bindListenNative
05-20 09:11:05.340 11550-11550/com.bluetooth2.app V/BluetoothSocket.cpp﹕ ...bindListenNative(43) success
05-20 09:11:05.340 11550-11550/com.bluetooth2.app V/BluetoothSocket.cpp﹕ abortNative
05-20 09:11:05.340 11550-11550/com.bluetooth2.app V/BluetoothSocket.cpp﹕ ...asocket_abort(43) complete
05-20 09:11:05.340 11550-11550/com.bluetooth2.app V/BluetoothSocket.cpp﹕ destroyNative
05-20 09:11:05.340 11550-11550/com.bluetooth2.app V/BluetoothSocket.cpp﹕ ...asocket_destroy(43) complete
05-20 09:11:05.340 11550-11550/com.bluetooth2.app E/ServerThread﹕ initialization: Not able to register SDP record for Usł‚uga witająca
05-20 09:11:05.340 11550-11550/com.bluetooth2.app V/BluetoothSocket.cpp﹕ initSocketNative
05-20 09:11:05.340 11550-11550/com.bluetooth2.app V/BluetoothSocket.cpp﹕ ...fd 43 created (RFCOMM, lm = 26)
05-20 09:11:05.340 11550-11550/com.bluetooth2.app V/BluetoothSocket.cpp﹕ initSocketFromFdNative
05-20 09:11:05.350 11550-11550/com.bluetooth2.app D/BluetoothUtils﹕ isSocketAllowedBySecurityPolicy start : device null
05-20 09:11:05.355 11550-11550/com.bluetooth2.app V/BluetoothSocket.cpp﹕ bindListenNative
05-20 09:11:05.355 11550-11550/com.bluetooth2.app V/BluetoothSocket.cpp﹕ ...bindListenNative(43) success
05-20 09:11:05.355 11550-11550/com.bluetooth2.app V/BluetoothSocket.cpp﹕ abortNative
05-20 09:11:05.355 11550-11550/com.bluetooth2.app V/BluetoothSocket.cpp﹕ ...asocket_abort(43) complete
05-20 09:11:05.355 11550-11550/com.bluetooth2.app V/BluetoothSocket.cpp﹕ destroyNative
05-20 09:11:05.355 11550-11550/com.bluetooth2.app V/BluetoothSocket.cpp﹕ ...asocket_destroy(43) complete
05-20 09:11:05.355 11550-11550/com.bluetooth2.app E/ServerThread﹕ initialization: Not able to register SDP record for Usł‚uga witająca
05-20 09:11:05.365 11550-11563/com.bluetooth2.app D/INFO﹕ Uruchamiam serwer
05-20 09:11:05.365 11550-11563/com.bluetooth2.app D/INFO﹕ Czekam na połączenie od clienta
05-20 09:11:05.370 11550-11563/com.bluetooth2.app W/dalvikvm﹕ threadid=11: thread exiting with uncaught exception (group=0x40df12a0)
05-20 09:11:05.370 11550-11563/com.bluetooth2.app E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-837
java.lang.NullPointerException
at com.bluetooth2.app.SerwerBluetooth.run(MainActivity.java:421)
05-20 09:11:05.385 11550-11552/com.bluetooth2.app D/dalvikvm﹕ GC_CONCURRENT freed 18K, 13% free 9915K/11335K, paused 12ms+2ms, total 31ms
05-20 09:11:05.430 11550-11550/com.bluetooth2.app D/libEGL﹕ loaded /system/lib/egl/libEGL_mali.so
05-20 09:11:05.435 11550-11550/com.bluetooth2.app D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_mali.so
05-20 09:11:05.440 11550-11550/com.bluetooth2.app D/libEGL﹕ loaded /system/lib/egl/libGLESv2_mali.so
05-20 09:11:05.440 11550-11550/com.bluetooth2.app D/﹕ Device driver API match
Device driver API version: 10
User space API version: 10
05-20 09:11:05.440 11550-11550/com.bluetooth2.app D/﹕ mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Thu Oct 25 08:43:05 KST 2012
05-20 09:11:05.455 11550-11550/com.bluetooth2.app D/OpenGLRenderer﹕ Enabling debug mode 0
05-20 09:11:13.035 11550-11550/com.bluetooth2.app I/Choreographer﹕ Skipped 457 frames! The application may be doing too much work on its main thread.
05-20 09:11:15.015 11550-11563/com.bluetooth2.app I/Process﹕ Sending signal. PID: 11550 SIG: 9
robiłem zgodnie z tym przykładem
http://andrzejklusiewicz-android.blogspot.com/2014/02/bluetooth-czyli-niebieskie-pogaduszki.html
i dalej nic
server start daje w brodcastRecaiver kiedy bluetooth się włączy
switch(state)
{
case(BluetoothAdapter.STATE_ON):
{
Toast.makeText(getApplicationContext(), getString(R.string.btON), Toast.LENGTH_SHORT).show();
SetVisibility();
btInit();
new SerwerBluetooth().start();
break;
}
.
.
.
.
.
już naprawdę nie mam pojęcie o co chodzi, jak nawet przykład ze strony androida nie działa
linia 421 to jest to Log.d("INFO","Czekam na połączenie od clienta");