BluetoothClient bc = new BluetoothClient(); BluetoothDeviceInfo[] devices; //BluetoothDeviceInfo info = null; Guid id = new Guid("{00112233-4455-6677-8899-aabbccddeeff}"); Console.WriteLine(id.ToString()); Console.WriteLine("Waiting......."); Console.ReadLine(); devices = bc.DiscoverDevices(); try { BluetoothListener bl = new BluetoothListener(id); bl.Start(); if (bl.AcceptSocket() != null) Console.WriteLine("Successfully Connected"); Console.Read(); } catch (Exception e) { Console.WriteLine("Exception : " + e.Message); Console.Read(); }
public class MainActivity extends Activity { BluetoothAdapter adapter; BluetoothDevice bd; BluetoothSocket sock; OutputStream ostr; int REQUEST_ENABLE_BT; String str="6C:AC:6C:DD:6C:0D"; // BlueTooth Device Id private static final UUID id=UUID.fromString("00112233-4455-6677-8899- aabbccddeeff"); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); adapter=BluetoothAdapter.getDefaultAdapter(); if (!adapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } Button b = (Button) findViewById( le="http://R.id">R.id.button1); b.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), "clicked button", Toast.LENGTH_LONG).show(); try { bd=adapter.getRemoteDevice(str); Toast.makeText(getApplicationContext(),"Server is running at "+bd.getName().toString()+"...", Toast.LENGTH_LONG).show(); sock=bd.createInsecureRfcommSocketToServiceRecord(id); sock.connect(); ostr=sock.getOutputStream(); ostr.write(0); } catch(Exception e) { Toast.makeText(getApplicationContext(),e.getMessage(), Toast.LENGTH_LONG).show(); } } }); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)