本文整理汇总了Java中javax.bluetooth.LocalDevice.getLocalDevice方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDevice.getLocalDevice方法的具体用法?Java LocalDevice.getLocalDevice怎么用?Java LocalDevice.getLocalDevice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.bluetooth.LocalDevice
的用法示例。
在下文中一共展示了LocalDevice.getLocalDevice方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例4: 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());
}
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
}
示例9: 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);
}
}
示例10: 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());
}
}
示例11: startInquiry
import javax.bluetooth.LocalDevice; //导入方法依赖的package包/类
/**
* Start device inquiry. Your application call this method to start inquiry.
* @param mode int one of DiscoveryAgent.GIAC or DiscoveryAgent.LIAC
* @param serviceUUIDs UUID[]
*/
public void startInquiry(int mode, UUID[] serviceUUIDs) {
try {
this.discoveryMode = mode;
this.serviceUUIDs = serviceUUIDs;
// clear previous values first
devices.removeAllElements();
deviceClasses.removeAllElements();
//
// initialize the JABWT stack
device = LocalDevice.getLocalDevice(); // obtain reference to singleton
device.setDiscoverable(DiscoveryAgent.GIAC); // set Discover Mode
agent = device.getDiscoveryAgent(); // obtain reference to singleton
boolean result = agent.startInquiry(mode, this.listener = new Listener());
// update screen with "Please Wait" message
remotedeviceui.setMsg("[Please Wait...]");
} catch (BluetoothStateException e) {
e.printStackTrace();
}
}
示例12: start
import javax.bluetooth.LocalDevice; //导入方法依赖的package包/类
public void start() {
try {
localDevice = LocalDevice.getLocalDevice();
address = Bluetooth
.formatAddress(localDevice.getBluetoothAddress());
logger.debug("Bluetooth stack type is {}",
LocalDevice.getProperty("bluecove.stack"));
logger.debug("Bluetooth name {}", localDevice.getFriendlyName());
logger.debug("Bluetooth address {}", address);
logger.debug("Bluetooth API Version {}",
LocalDevice.getProperty("bluetooth.api.version"));
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("BluetoothServer");
thread.start();
bluetoothSupported = true;
} catch (Throwable t) {
logger.debug("Bluetooth not supported due to {}", t.toString());
}
}
示例13: main
import javax.bluetooth.LocalDevice; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
//display local device address and name
LocalDevice localDevice = LocalDevice.getLocalDevice();
System.out.println("Address: "+localDevice.getBluetoothAddress());
System.out.println("Name: "+localDevice.getFriendlyName());
BTServer BTCommand=new BTServer();
BTCommand.startServer();
}
示例14: getMoteFinder
import javax.bluetooth.LocalDevice; //导入方法依赖的package包/类
/**
* Returns the <code>WiimoteFinder</code> instance.
*
* @return WiimoteFinder
*/
public static MoteFinder getMoteFinder() {
try {
// disable PSM minimum flag because the wiimote has a PSM below 0x1001
System.setProperty(BlueCoveConfigProperties.PROPERTY_JSR_82_PSM_MINIMUM_OFF, "true");
SingletonHolder.INSTANCE.localDevice = LocalDevice.getLocalDevice();
SingletonHolder.INSTANCE.discoveryAgent = SingletonHolder.INSTANCE.localDevice.getDiscoveryAgent();
return SingletonHolder.INSTANCE;
} catch (BluetoothStateException ex) {
throw new RuntimeException(ex);
}
}
示例15: Main
import javax.bluetooth.LocalDevice; //导入方法依赖的package包/类
public Main(){
mainContainer = new ScreensController(this);
mainContainer.loadScreen("ChatScreen","ChatScreen.fxml");
mainContainer.loadScreen("StartScreen","StartScreen.fxml");
mainContainer.loadScreen("LoadingScreen","LoadingScreen.fxml");
mainContainer.loadScreen("ServerListScreen","ServerListScreen.fxml");
mainContainer.setScreen("StartScreen");
try {
LocalDevice localDevice = LocalDevice.getLocalDevice();
myName = localDevice.getFriendlyName();
} catch (BluetoothStateException e) {
e.printStackTrace();
}
}