java - Connecting pc to android phone using bluetooth -


I want to set up a Bluetooth connection between my PC and Android phone and want to send the string to Android phone from my PC. I'm using Bluecove 2.1.0 I'm able to find nearby Bluetooth devices. Now I want to add the devices and send the string to the Android phone from the PC Thanks, in advance, this is the device that I am looking for device

  import java.io .OutputStream; Import java.util.ArrayList; Import javax.bluetooth.DataElement; Import javax.bluetooth.DeviceClass; Import javax.bluetooth.DiscoveryAgent; Import javax.bluetooth.DiscoveryListener; Import javax.bluetooth.LocalDevice; Import javax.bluetooth.RemoteDevice; Import javax.bluetooth.ServiceRecord; Import javax.bluetooth.UUID; Import javax.microedition.io.Connector; Import javax.obex.ClientSession; Import javax.obex.HeaderSet; Import javax.obex.Operation; Import javax.obex.ResponseCodes; Public class MyDiscoveryListener DiscoveryListener applied {Private station object lock = new object (); Public Arrestist & lt; Remote device & gt; equipment; Public MyDiscoveryListener () {devices = New ArrayList & lt; RemoteDevice & gt; (); } Public static zero main (string [] args) {MyDiscoveryListener listener = new MyDiscoveryListener (); {Try LocalDevice localDevice = LocalDevice.getLocalDevice (); Discovery Agent Agent = localDevice.getDiscoveryAgent (); Agent.startInquiry (DiscoveryAgent.GIAC, listener); Try {synchronize (lock) {lock.wait (); }} Grip (interrupted e) e.printStackTrace (); Return; } System.out.println ("Complete the device check."); UUID [] UUIDset = new UUID [1]; UuidSet [0] = new UUID (0x1105); // obex object push service int [] attrIDs = new int [] {0x0100 // service name}; (Remote device device: listener.devices) (agent.searchServices (attrids, uuidSet, device, listener); try {synchronize (lock) {lock.wait ();}} grip (interrupted ejection e) {e.printStackTrace (); Return;} System.out.println ("Service Search Ended.");}} Hold (Exception e) {e.printStackTrace ();}} @ Override Public Video Device Detected (Remote Device BTDevice, DeviceClass AG 1) {string name; try {name = btDevice.getFriendlyName (wrong);} hold (exception e) {name = btDevice.getBluetoothAddress ();} devices.add (btDevice); System.out.println ("Device found:" + no Override Public Null Service Search Full (Integury, Int arg1) {Synchronize (lock) {lock} .notify ();}} @ Override Public Zero Services Detected (Ent Transgy, Service Record [] AllCarord) {For (Int i = 0; I & lt; servRecord.length; i ++) {string URL = Servercard [i] .getConnectionURL (service record. Nyuthentic dooncCRPT, incorrect); If (URL == empty) {continue; } DataAverage ServiceNew = ServerCode [i] .getAttributeValue (0x0100); If (serviceName! = Tap) {System.out.println ("service" + serviceName.getValue () + "found" + url); If (serviceName.getValue (.) Equals ("push obex object")) {sendMessageToDevice (url); }} And {System.out.println ("service found" + url); }}} Private steak blank sendMessageToDevice {string server URL} {try {system.out.println ("Connect" + server URL); Client session client session = (client session) connector. Open (server URL); Headset hsConnectReply = client session. Connect (tap); If (hsConnectReply.getResponseCode ()! = ResponseCodes.OBEX_HTTP_OK) {System.out.println ("Failed to connect"); Return; } HeaderSet hsOperation = clientSession.createHeaderSet (); HsOperation.setHeader (Header. NAME, "Hello.txt"); HsOperation.setHeader (HeaderSet.TYPE, "text"); // Set the PUT Operation Operation = Client session. Input (HS operation); // Send some text to server byte data [] = "Hello World !!!" getBytes ("iso-885 9-1"); OutputStream OS = (putOperation) .openOutputStream (); os.write (data); Os.close (); putOperation.close (); clientSession.disconnect (zero); clientSession.close (); } Hold (exception e) {e.printStackTrace (); I finally got it - this is my link to my repository. MyDiscoveryListener is a link to my repository. java takes all actions   

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -