本文整理汇总了Java中javax.bluetooth.LocalDevice类的典型用法代码示例。如果您正苦于以下问题:Java LocalDevice类的具体用法?Java LocalDevice怎么用?Java LocalDevice使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LocalDevice类属于javax.bluetooth包,在下文中一共展示了LocalDevice类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendBluetoothMessage
import javax.bluetooth.LocalDevice; //导入依赖的package包/类
/**
* if bluetooth connection is available, <code>sendBluetoothMessage()</code> run <code>sendReciveMessageThread()</code>.
* Else, checks if Bluetooth is activated and chooses if close connection or wait again
*/
void sendBluetoothMessage() {
if (connectionIsAvaible) {
if (outStream != null) {
if (sendReciveMessageThread.isInterrupted()) {
messageThreadExecutor.execute(sendReciveMessageThread);
System.out.println("thread creato e avviato");
sendBluetoothMessage();
} else {
sendReciveMessageThread.interrupt();
messageThreadExecutor.execute(sendReciveMessageThread);
}
}
} else {
try {
if (LocalDevice.getLocalDevice() != null && !LocalDevice.getLocalDevice().getFriendlyName().equals("null"))
System.out.println("connessione non stabilita " + LocalDevice.getLocalDevice().getFriendlyName());
else {
closeConnection();
}
} catch (BluetoothStateException | NullPointerException e) {
e.printStackTrace();
closeConnection();
}
}
}
示例2: getLocalAddress
import javax.bluetooth.LocalDevice; //导入依赖的package包/类
private Optional<String> getLocalAddress() {
try {
final LocalDevice localDevice = LocalDevice.getLocalDevice();
// Insert colons into the address because android needs them
final StringBuilder addressBuilder = new StringBuilder();
final String originalAddress = localDevice.getBluetoothAddress();
for (int i = 0; i < originalAddress.length(); i++) {
addressBuilder.append(originalAddress.charAt(i));
if (i > 0 && i < originalAddress.length() - 1 && i % 2 != 0) addressBuilder.append(':');
}
return Optional.of(addressBuilder.toString());
} catch (BluetoothStateException e) {
logger.error("Failed to access local bluetooth device to fetch its address. Ensure the "
+ "system's bluetooth service is started with \"sudo systemctl start bluetooth\" "
+ "and the bluetooth stack is on in the system settings", e);
return Optional.empty();
}
}
示例3: PAKBluetoothPairingHandler
import javax.bluetooth.LocalDevice; //导入依赖的package包/类
public PAKBluetoothPairingHandler(String password, String eMail,
String firstName, String lastName, String deviceName,
X509Certificate ownerCertEnc, X509Certificate ownerCertSign,
Map<String, X509Certificate> knownDevices,
Collection<VCard> knownContacts) throws IOException {
super(PairingType.SLAVE, password, eMail, firstName, lastName,
deviceName, ownerCertEnc, ownerCertSign, knownDevices,
knownContacts);
UUID uuid = new UUID(0x1101); // TODO: Create new unique UUID
String connectionString = "btspp://localhost:" + uuid
+ ";name=PanboxImportListener;encrypt=false;authenticate=false";
streamConnNotifier = (StreamConnectionNotifier) Connector.open(
connectionString, Connector.READ_WRITE);
ServiceRecord record = LocalDevice.getLocalDevice().getRecord(
streamConnNotifier);
logger.debug("PAKBluetoothPairingHandler : connection is up at: "
+ record.getConnectionURL(0, false));
}
示例4: initDevicePairingBluetooth
import javax.bluetooth.LocalDevice; //导入依赖的package包/类
public BluetoothPairingInformation initDevicePairingBluetooth()
throws BluetoothStateException, InterruptedException {
// This is the first time we are going to touch the Bluetooth API so we
// should attach our logger to the com.intel.bluetooth logging
appendBluetoothLogging();
// Make bluetooth device discoverbale!
LocalDevice local = LocalDevice.getLocalDevice();
try {
local.setDiscoverable(DiscoveryAgent.GIAC);
} catch (BluetoothStateException e) {
logger.debug(
"PanboxClient : initDevicePairingBluetooth : First try to set discoverable failed. Will try again in 1sec.");
Thread.sleep(1000);
local.setDiscoverable(DiscoveryAgent.GIAC);
}
// setting LocalDevice is only need for Linux, since on Windows we
// bluecove only supports one device!
BluetoothPairingInformation info = new BluetoothPairingInformation(local);
extendPairingInformation(info);
return info;
}
示例5: main
import javax.bluetooth.LocalDevice; //导入依赖的package包/类
public static void main(String args[]) {
try {
LocalDevice local = LocalDevice.getLocalDevice();
System.out.println("Server Started:\n"
+ local.getBluetoothAddress()
+ "\n" + local.getFriendlyName());
rfcommserver ff = new rfcommserver();
while (true) {
ff.startserver();
} //while
} //try
catch (Exception e) {
System.err.print(e.toString());
}
}
示例6: start
import javax.bluetooth.LocalDevice; //导入依赖的package包/类
public boolean start() throws IOException {
// Initialise the Bluetooth stack
try {
localDevice = LocalDevice.getLocalDevice();
} catch(UnsatisfiedLinkError e) {
// On Linux the user may need to install libbluetooth-dev
if(OsUtils.isLinux())
callback.showMessage("BLUETOOTH_INSTALL_LIBS");
return false;
}
if(LOG.isLoggable(INFO))
LOG.info("Local address " + localDevice.getBluetoothAddress());
running = true;
bind();
return true;
}
示例7: MonitoringThreadImpl
import javax.bluetooth.LocalDevice; //导入依赖的package包/类
/**
* Creates a new instance.
*
*/
MonitoringThreadImpl() throws BluetoothException
{
super("Bluetooth Monitoring"); //$NON-NLS-1$
try
{
this.localDevice = LocalDevice.getLocalDevice();
}
catch (BluetoothStateException e)
{
throw new BluetoothException(e.getMessage());
}
this.localAddress = localDevice.getBluetoothAddress();
this.localName = localDevice.getFriendlyName();
this.discoveryAgent = localDevice.getDiscoveryAgent();
logger.debug("LocalAdress: " + localAddress + ", Name: " + localName); //$NON-NLS-1$ //$NON-NLS-2$
this.monitoringListeners = new ArrayList();
this.discoveryInProgress = false;
this.pass = 0;
}
示例8: init
import javax.bluetooth.LocalDevice; //导入依赖的package包/类
/**
* Process the search/download requests.
*/
public void init() {
try {
// create/get a local device and discovery agent
LocalDevice localDevice = LocalDevice.getLocalDevice();
discoveryAgent = localDevice.getDiscoveryAgent();
} catch (Exception e) {
eventListener.errorOccured("Can't initialize bluetooth: ", e);
System.err.println("Can't initialize bluetooth: " + e);
}
// initialize some optimization variables
uuidSet = new UUID[2];
// ok, we are interesting in btspp services only
uuidSet[0] = new UUID(0x1101);
// and only known ones, that allows pictures
uuidSet[1] = SERVER_UUID;
}
示例9: startServiceSearch
import javax.bluetooth.LocalDevice; //导入依赖的package包/类
/**
*
* This method is used to re-establish a connection to a device when we have the address.
*
* @param address The address to the device
*/
public void startServiceSearch(String address){
// Connects to a remote device with the given address
RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
try{
localDevice = LocalDevice.getLocalDevice();
agent = localDevice.getDiscoveryAgent();
uuids[0] = new UUID(uuidString, false);
servicesFound = new Vector();
devicesFound = new Vector();
agent.searchServices(attributes,uuids,remoteDevice,this);
}catch(BluetoothStateException bse) {
log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
// throw bse;
}
}
示例10: printLocalDevice
import javax.bluetooth.LocalDevice; //导入依赖的package包/类
public static void printLocalDevice(LocalDevice dev) {
System.out.println("Print Local Device " + dev.getBluetoothAddress());
System.out.println("Name: " + dev.getFriendlyName());
DeviceClass devClass = dev.getDeviceClass();
if (devClass != null) {
System.out.println("MajorDevice:"
+ majorToName(devClass.getMajorDeviceClass()));
System.out.println("MinorDevice:"
+ minorToName(devClass.getMajorDeviceClass(),
devClass.getMinorDeviceClass()));
System.out.println("ServiceClass:");
String[] str = Util.majorServiceToName(devClass.getServiceClasses());
for (int i = 0; i < str.length; i++) {
System.out.println(" " + str[i]);
}
}
}
示例11: BluetoothServer
import javax.bluetooth.LocalDevice; //导入依赖的package包/类
private BluetoothServer() {
clients = new ConcurrentHashMap<Integer, BluetoothClient>();
try {
device = LocalDevice.getLocalDevice();
if (device != null) {
if (!LocalDevice.isPowerOn()) {
System.out.println("Device power is off. Turn it on!");
System.exit(1);
}
} else {
System.out.println("No device");
System.exit(1);
}
} catch (BluetoothStateException e) {
System.out.println(e.getMessage());
System.exit(1);
}
}
示例12: start
import javax.bluetooth.LocalDevice; //导入依赖的package包/类
public void start() {
try {
localDevice = LocalDevice.getLocalDevice();
address = Bluetooth
.formatAddress(localDevice.getBluetoothAddress());
try {
if (!localDevice.setDiscoverable(DiscoveryAgent.GIAC)) {
logger.debug("Could not set discoverable to GIAC");
}
} catch (Throwable sd) {
logger.debug("Could not set discoverable to GIAC", sd);
}
thread = new BluetoothServerThread();
thread.setName("BluetoothMouseMoveServer");
thread.start();
bluetoothSupported = true;
} catch (Throwable t) {
logger.debug("Bluetooth not supported due to {}", t.toString());
}
}
示例13: initCommunication
import javax.bluetooth.LocalDevice; //导入依赖的package包/类
@Override
public void initCommunication() throws Exception {
this.dataInputStream = new ObjectInputStream(
connection.openDataInputStream());
this.dataOutputStream = new ObjectOutputStream(
connection.openDataOutputStream());
this.idA = RemoteDevice.getRemoteDevice(connection)
.getBluetoothAddress();
this.idB = LocalDevice.getLocalDevice().getBluetoothAddress();
}
示例14: getNodeAddress
import javax.bluetooth.LocalDevice; //导入依赖的package包/类
/**
*
* This method returns the node address.
*
* @param input String "localNode" to retreive the address of the local device.
* A ServiceRecord or StreamConnection object to retreive the address of a
* remote device.
*
* @return The node network address.
* @throws IOException
*/
public String getNodeAddress(Object input) throws IOException{
// Checks whether the input is a String and the String equals "localnode".
// If so the address of the LocalDevice is returned.
if(input.getClass().isInstance(new String())){
String inputString = (String)input;
// Make sure that we won't get any UPPER/lower case problems
inputString.toLowerCase();
if(inputString.equals("localnode"))return LocalDevice.getLocalDevice().getBluetoothAddress();
}
// Input type is object because superclass cannot relate to ServiceRecord which is a bluetooth specific class.
// This method is valid either the input type is ServiceRecord or StreamConnection.
RemoteDevice remoteDevice = null;
try{
ServiceRecord serviceRecord = (ServiceRecord) input;
remoteDevice = serviceRecord.getHostDevice();
}catch(ClassCastException cce1){
// Could not cast the input object to ServiceRecord. Trying streamConnection instead ;-)
try{
StreamConnection streamConnection = (StreamConnection) input;
remoteDevice = RemoteDevice.getRemoteDevice(streamConnection);
}catch(ClassCastException cce2){
//This will only happen if the input object type is wrong
log.logException("BluetoothNetwork.getNodeAddress()",cce2,false);
}catch(IOException ioe){
log.logException("BluetoothNetwork.getNodeAddress()",ioe,false);
throw ioe;
}
}
return remoteDevice.getBluetoothAddress();
}