List of usage examples for android.bluetooth BluetoothDevice getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.cypress.cysmart.RDKEmulatorView.RemoteControlEmulatorFragment.java
private void pairDevice(BluetoothDevice device) { try {//from w w w . j av a 2 s . c om Method m = device.getClass().getMethod("createBond", (Class[]) null); m.invoke(device, (Object[]) null); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.filterdevice.ProfileScanningFragment.java
private void pairDevice(BluetoothDevice device) { try {// w ww. j ava 2 s. co m Method m = device.getClass().getMethod("createBond", (Class[]) null); m.invoke(device, (Object[]) null); } catch (Exception e) { if (mProgressdialog != null && mProgressdialog.isShowing()) { mProgressdialog.dismiss(); } } }
From source file:com.filterdevice.ProfileScanningFragment.java
private void unpairDevice(BluetoothDevice device) { try {//from w w w . j ava 2 s .c o m Method m = device.getClass().getMethod("removeBond", (Class[]) null); m.invoke(device, (Object[]) null); } catch (Exception e) { if (mProgressdialog != null && mProgressdialog.isShowing()) { mProgressdialog.dismiss(); } } }
From source file:com.phonegap.plugin.BluetoothPlugin.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { Log.d(LOG_TAG, "Plugin Called"); this.callbackContext = callbackContext; PluginResult result = null;/*from w ww . jav a2s .c om*/ //Looper.prepare(); btadapter = BluetoothAdapter.getDefaultAdapter(); found_devices = new ArrayList<BluetoothDevice>(); if (ACTION_DISCOVER_DEVICES.equals(action)) { try { Log.d(LOG_TAG, "We're in " + ACTION_DISCOVER_DEVICES); found_devices.clear(); discovering = true; if (btadapter.isDiscovering()) { btadapter.cancelDiscovery(); } Log.i(LOG_TAG, "Discovering devices..."); btadapter.startDiscovery(); result = new PluginResult(PluginResult.Status.NO_RESULT); result.setKeepCallback(true); } catch (Exception Ex) { Log.d("BluetoothPlugin - " + ACTION_DISCOVER_DEVICES, "Got Exception " + Ex.getMessage()); result = new PluginResult(PluginResult.Status.ERROR); } } else if (ACTION_IS_BT_ENABLED.equals(action)) { try { Log.d(LOG_TAG, "We're in " + ACTION_IS_BT_ENABLED); boolean isEnabled = btadapter.isEnabled(); Log.d("BluetoothPlugin - " + ACTION_IS_BT_ENABLED, "Returning " + "is Bluetooth Enabled? " + isEnabled); result = new PluginResult(PluginResult.Status.OK, isEnabled); } catch (Exception Ex) { Log.d("BluetoothPlugin - " + ACTION_IS_BT_ENABLED, "Got Exception " + Ex.getMessage()); result = new PluginResult(PluginResult.Status.ERROR); } } else if (ACTION_ENABLE_BT.equals(action)) { try { Log.d(LOG_TAG, "We're in " + ACTION_ENABLE_BT); boolean enabled = false; Log.d(LOG_TAG, "Enabling Bluetooth..."); if (btadapter.isEnabled()) { enabled = true; } else { enabled = btadapter.enable(); } Log.d("BluetoothPlugin - " + ACTION_ENABLE_BT, "Returning " + "Result: " + enabled); result = new PluginResult(PluginResult.Status.OK, enabled); } catch (Exception Ex) { Log.d("BluetoothPlugin - " + ACTION_ENABLE_BT, "Got Exception " + Ex.getMessage()); result = new PluginResult(PluginResult.Status.ERROR); } } else if (ACTION_DISABLE_BT.equals(action)) { try { Log.d(LOG_TAG, "We're in " + ACTION_DISABLE_BT); boolean disabled = false; Log.d(LOG_TAG, "Disabling Bluetooth..."); if (btadapter.isEnabled()) { disabled = btadapter.disable(); } else { disabled = true; } Log.d("BluetoothPlugin - " + ACTION_DISABLE_BT, "Returning " + "Result: " + disabled); result = new PluginResult(PluginResult.Status.OK, disabled); } catch (Exception Ex) { Log.d("BluetoothPlugin - " + ACTION_DISABLE_BT, "Got Exception " + Ex.getMessage()); result = new PluginResult(PluginResult.Status.ERROR); } } else if (ACTION_PAIR_BT.equals(action)) { try { Log.d(LOG_TAG, "We're in " + ACTION_PAIR_BT); String addressDevice = args.getString(0); if (btadapter.isDiscovering()) { btadapter.cancelDiscovery(); } BluetoothDevice device = btadapter.getRemoteDevice(addressDevice); boolean paired = false; Log.d(LOG_TAG, "Pairing with Bluetooth device with name " + device.getName() + " and address " + device.getAddress()); try { Method m = device.getClass().getMethod("createBond"); paired = (Boolean) m.invoke(device); } catch (Exception e) { e.printStackTrace(); } Log.d("BluetoothPlugin - " + ACTION_PAIR_BT, "Returning " + "Result: " + paired); result = new PluginResult(PluginResult.Status.OK, paired); } catch (Exception Ex) { Log.d("BluetoothPlugin - " + ACTION_PAIR_BT, "Got Exception " + Ex.getMessage()); result = new PluginResult(PluginResult.Status.ERROR); } } else if (ACTION_UNPAIR_BT.equals(action)) { try { Log.d(LOG_TAG, "We're in " + ACTION_UNPAIR_BT); String addressDevice = args.getString(0); if (btadapter.isDiscovering()) { btadapter.cancelDiscovery(); } BluetoothDevice device = btadapter.getRemoteDevice(addressDevice); boolean unpaired = false; Log.d(LOG_TAG, "Unpairing Bluetooth device with " + device.getName() + " and address " + device.getAddress()); try { Method m = device.getClass().getMethod("removeBond"); unpaired = (Boolean) m.invoke(device); } catch (Exception e) { e.printStackTrace(); } Log.d("BluetoothPlugin - " + ACTION_UNPAIR_BT, "Returning " + "Result: " + unpaired); result = new PluginResult(PluginResult.Status.OK, unpaired); } catch (Exception Ex) { Log.d("BluetoothPlugin - " + ACTION_UNPAIR_BT, "Got Exception " + Ex.getMessage()); result = new PluginResult(PluginResult.Status.ERROR); } } else if (ACTION_LIST_BOUND_DEVICES.equals(action)) { try { Log.d(LOG_TAG, "We're in " + ACTION_LIST_BOUND_DEVICES); Log.d(LOG_TAG, "Getting paired devices..."); Set<BluetoothDevice> pairedDevices = btadapter.getBondedDevices(); int count = 0; String resultBoundDevices = "[ "; if (pairedDevices.size() > 0) { for (BluetoothDevice device : pairedDevices) { Log.i(LOG_TAG, device.getName() + " " + device.getAddress() + " " + device.getBondState()); if ((device.getName() != null) && (device.getBluetoothClass() != null)) { resultBoundDevices = resultBoundDevices + " { \"name\" : \"" + device.getName() + "\" ," + "\"address\" : \"" + device.getAddress() + "\" ," + "\"class\" : \"" + device.getBluetoothClass().getDeviceClass() + "\" }"; if (count < pairedDevices.size() - 1) resultBoundDevices = resultBoundDevices + ","; } else Log.i(LOG_TAG, device.getName() + " Problems retrieving attributes. Device not added "); count++; } } resultBoundDevices = resultBoundDevices + "] "; Log.d("BluetoothPlugin - " + ACTION_LIST_BOUND_DEVICES, "Returning " + resultBoundDevices); result = new PluginResult(PluginResult.Status.OK, resultBoundDevices); } catch (Exception Ex) { Log.d("BluetoothPlugin - " + ACTION_LIST_BOUND_DEVICES, "Got Exception " + Ex.getMessage()); result = new PluginResult(PluginResult.Status.ERROR); } } else if (ACTION_STOP_DISCOVERING_BT.equals(action)) { try { Log.d(LOG_TAG, "We're in " + ACTION_STOP_DISCOVERING_BT); boolean stopped = true; Log.d(LOG_TAG, "Stop Discovering Bluetooth Devices..."); if (btadapter.isDiscovering()) { Log.i(LOG_TAG, "Stop discovery..."); stopped = btadapter.cancelDiscovery(); discovering = false; } Log.d("BluetoothPlugin - " + ACTION_STOP_DISCOVERING_BT, "Returning " + "Result: " + stopped); result = new PluginResult(PluginResult.Status.OK, stopped); } catch (Exception Ex) { Log.d("BluetoothPlugin - " + ACTION_STOP_DISCOVERING_BT, "Got Exception " + Ex.getMessage()); result = new PluginResult(PluginResult.Status.ERROR); } } else if (ACTION_IS_BOUND_BT.equals(action)) { try { Log.d(LOG_TAG, "We're in " + ACTION_IS_BOUND_BT); String addressDevice = args.getString(0); BluetoothDevice device = btadapter.getRemoteDevice(addressDevice); Log.i(LOG_TAG, "BT Device in state " + device.getBondState()); boolean state = false; if (device != null && device.getBondState() == 12) state = true; else state = false; Log.d(LOG_TAG, "Is Bound with " + device.getName() + " - address " + device.getAddress()); Log.d("BluetoothPlugin - " + ACTION_IS_BOUND_BT, "Returning " + "Result: " + state); result = new PluginResult(PluginResult.Status.OK, state); } catch (Exception Ex) { Log.d("BluetoothPlugin - " + ACTION_IS_BOUND_BT, "Got Exception " + Ex.getMessage()); result = new PluginResult(PluginResult.Status.ERROR); } /* } else if ( ACTION_READ.equals(action) ) { final int socketId = args.getInt(0); final int bufferSize = args.getInt(1); this.callback_read = callbackContext; ReadThread readThread = new ReadThread( m_sockets.get(socketId),socketId,bufferSize); readThread.start(); m_readThreads.add(readThread); PluginResult pluginResult = new PluginResult( PluginResult.Status.NO_RESULT); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); return true; */ } else { result = new PluginResult(PluginResult.Status.INVALID_ACTION); Log.d(LOG_TAG, "Invalid action : " + action + " passed"); } this.callbackContext.sendPluginResult(result); return true; }
From source file:com.cypress.cysmart.CommonFragments.ProfileScanningFragment.java
private void pairDevice(BluetoothDevice device) { try {/*from w w w. j a v a2 s .com*/ Method m = device.getClass().getMethod("createBond", (Class[]) null); m.invoke(device, (Object[]) null); } catch (Exception e) { if (mpdia != null && mpdia.isShowing()) { mpdia.dismiss(); } } }
From source file:com.cypress.cysmart.CommonFragments.ProfileScanningFragment.java
private void unpairDevice(BluetoothDevice device) { try {//from w w w . j av a 2 s . c om Method m = device.getClass().getMethod("removeBond", (Class[]) null); m.invoke(device, (Object[]) null); } catch (Exception e) { if (mpdia != null && mpdia.isShowing()) { mpdia.dismiss(); } } }
From source file:edu.stanford.junction.provider.bluetooth.Junction.java
private BluetoothSocket createBluetoothSocket(BluetoothDevice device, UUID uuid) throws IOException { BluetoothSocket tmp;/*from w w w.ja v a 2 s .c o m*/ if (mConfig.securePairingRequired() || VERSION.SDK_INT < VERSION_CODES.GINGERBREAD_MR1) { tmp = device.createRfcommSocketToServiceRecord(uuid); if (DBG) Log.d(TAG, "Using secure bluetooth socket"); } else { try { // compatibility with pre SDK 10 devices Method listener = device.getClass().getMethod("createInsecureRfcommSocketToServiceRecord", UUID.class); tmp = (BluetoothSocket) listener.invoke(device, uuid); if (DBG) Log.d(TAG, "Using insecure bluetooth socket"); } catch (NoSuchMethodException e) { Log.wtf(TAG, "createInsecureRfcommSocketToServiceRecord not found"); throw new IOException(e); } catch (InvocationTargetException e) { Log.wtf(TAG, "createInsecureRfcommSocketToServiceRecord not available on mBtAdapter"); throw new IOException(e); } catch (IllegalAccessException e) { Log.wtf(TAG, "createInsecureRfcommSocketToServiceRecord not available on mBtAdapter"); throw new IOException(e); } } return tmp; }
From source file:de.bogutzky.psychophysiocollector.app.MainActivity.java
private void pairBluetoothDevice(BluetoothDevice device) { try {//from w w w. j ava 2 s. co m Method method = device.getClass().getMethod("createBond", (Class[]) null); method.invoke(device, (Object[]) null); } catch (Exception e) { Log.e(TAG, "Error during the pairing", e); } }
From source file:com.kjsaw.alcosys.ibacapp.IBAC.java
private void unpairDevice(BluetoothDevice device) { try {//from ww w.j a v a 2s . c om Log.d("sam22", "Start Un-Pairing..."); Method m = device.getClass().getMethod("removeBond", (Class[]) null); m.invoke(device, (Object[]) null); Log.d("sam22", "Un-Pairing finished."); } catch (Exception e) { Log.e(TAG, e.getMessage()); } }
From source file:com.kjsaw.alcosys.ibacapp.IBAC.java
private void pairDevice(BluetoothDevice device) { try {/*w w w .j a v a 2 s .c om*/ Log.d("sam22", "Start Pairing..."); Method m = device.getClass().getMethod("createBond", (Class[]) null); //device.getClass().getMethod("setTrust", boolean.class).invoke(device); device.getClass().getMethod("cancelPairingUserInput", boolean.class).invoke(device); /** byte[] pin = ByteBuffer.allocate(4).putInt(1234).array(); //int pinn = 1234; //Entering pin programmatically: Method ms = device.getClass().getMethod("setPin", byte[].class); //Method ms = device.getClass().getMethod("setPasskey", int.class); ms.invoke(device, pin); **/ m.invoke(device, (Object[]) null); Log.d("sam22", "Pairing finished."); } catch (Exception e) { Log.e("pairDevice()", e.getMessage()); } }