Forked from crazycoder1999/androidbtserver.java
Last active
August 29, 2015 14:12
Revisions
-
crazycoder1999 revised this gist
Aug 1, 2012 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,8 +12,7 @@ public BluetoothAdapter findMyBT(BluetoothAdapter myBt){ } } //ask to enable BT to user public void enableMyBT(BluetoothAdapter myBt) { if ( ! myBt.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); @@ -33,7 +32,7 @@ public void beVisible() { //this methoed must run inside a thread. private void listenForConnection() { try{ BluetoothServerSocket bss = myBT.listenUsingRfcommWithServiceRecord("YOURSERVICENAME", UUID); //the UUID need to be GENERATED bs = bss.accept(); bss.close(); out = bs.getOutputStream(); -
crazycoder1999 created this gist
Aug 1, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ //Main necessary methoeds // get the bluetooth device reference public BluetoothAdapter findMyBT(BluetoothAdapter myBt){ myBt = BluetoothAdapter.getDefaultAdapter(); if (myBt!= null) { Log.i("BTDEV","BT Device Found!"); Log.i("BTDEV","" + myBt.getName()); return myBt; } else { Log.i("BTDEV","No BT Device Found!"); return null; } } //ask to enable BT to user.. what Happenend if it answer NO? Should I have to check that REQUEST_ENABLE_BT? //only if it is enable. public void enableMyBT(BluetoothAdapter myBt) { if ( ! myBt.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); actv.startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } } //ask to be visible for <visibility> seconds. public void beVisible() { Log.i("BTDEV","Let me be visible. thanks."); Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, visibility); this.actv.startActivity(discoverableIntent); } ///start listening for incoming data //this methoed must run inside a thread. private void listenForConnection() { try{ BluetoothServerSocket bss = myBT.listenUsingRfcommWithServiceRecord(this.serviceName, BtConstants.btUUID); bs = bss.accept(); bss.close(); out = bs.getOutputStream(); out.write("goodbye".getBytes()); //send a message //.... out.close(); //close it bs.close(); } catch (IOException e) { e.printStackTrace(); } }