Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

java - Detect hidden bluetooth device with known ID

I have the target bluetooth device MAC-ID and would like to see if it is in range. How can I establish a connection to the target device, if i have it's ID and it's in hidden mode?

I'm using bluecove (java) for this.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I'm not sure what you mean by "hidden mode." You can connect to a device that is not discoverable, but you cannot connect to a device that is not connectable.

Generally, using JSR-82 (or Bluecove, a JSR-82 implementation) you need to have a RemoteDevice object in order to open a connection. The only way to get a RemoteDevice is via device search. It looks like you can't do a device search in your case, as the device is "hidden."

In Bluecove, you'll notice that RemoteDevice has a protected constructor that takes a Bluetooth address String. You can create a subclass of RemoteDevice that simply makes that constructor public. For example:

public class MyRemoteDevice extends javax.Bluetooth.RemoteDevice {
  public MyRemoteDevice(String addr) {
    super(addr);
  }
}

You can then create an instance of MyRemoteDevice, passing it the known MAC address, and use it to open the connection.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...