List of usage examples for android.bluetooth BluetoothDevice getName
@RequiresPermission(Manifest.permission.BLUETOOTH)
public String getName()
From source file:org.apache.cordova.sipkita.BluetoothPrinter.java
boolean findBT(CallbackContext callbackContext, String name) { try {/*w w w .j a va2 s .com*/ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothPort = BluetoothPort.getInstance(); if (mBluetoothAdapter == null) { Log.e(LOG_TAG, "No bluetooth adapter available"); } if (!mBluetoothAdapter.isEnabled()) { Intent enableBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); this.cordova.getActivity().startActivityForResult(enableBluetooth, 0); } Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices(); if (pairedDevices.size() > 0) { for (BluetoothDevice device : pairedDevices) { // MP300 is the name of the bluetooth printer device if (device.getName().equalsIgnoreCase(name)) { mmDevice = device; return true; } } } Log.d(LOG_TAG, "Bluetooth Device Found: " + mmDevice.getName()); } catch (Exception e) { String errMsg = e.getMessage(); Log.e(LOG_TAG, errMsg); e.printStackTrace(); callbackContext.error(errMsg); } return false; }
From source file:ch.ethz.inf.vs.a1.fabischn.ble.MainActivity.java
@Override protected void onListItemClick(ListView l, View v, int position, long id) { final BluetoothDevice device = mLeDeviceListAdapter.getDevice(position); if (device == null) return;//w w w . ja va2 s.com final Intent intent = new Intent(this, DeviceControlActivity.class); intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_NAME, device.getName()); intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_ADDRESS, device.getAddress()); if (mScanning) { // mBluetoothAdapter.stopLeScan(mLeScanCallback); mBluetoothLeScanner.stopScan(mScanCallback); mScanning = false; } startActivity(intent); }
From source file:com.googlecode.android_scripting.facade.BluetoothFacade.java
@Rpc(description = "Queries a remote device for it's name or null if it can't be resolved") public String bluetoothGetRemoteDeviceName( @RpcParameter(name = "address", description = "Bluetooth Address For Target Device") String address) { try {/* w w w. ja v a 2 s.c o m*/ BluetoothDevice mDevice; mDevice = mBluetoothAdapter.getRemoteDevice(address); return mDevice.getName(); } catch (Exception e) { return null; } }
From source file:com.example.smsquickform.Homescreen.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_homescreen); ActivityHelper.initialize(this); //This is to ensure that the rotation persists across activities and not just this one Log.d(TAG, "Created"); Intent intent = getIntent();/*from w w w . j a va 2 s . c om*/ mBtnSearch = (Button) findViewById(R.id.btnSearch); mBtnConnect = (Button) findViewById(R.id.btnConnect); mButtonAnak = (Button) findViewById(R.id.buttonAnak); mButtonIbu = (Button) findViewById(R.id.buttonIbu); heading = (TextView) findViewById(R.id.txtListHeading); mLstDevices = (ListView) findViewById(R.id.lstDevices); /* *Check if there is a savedInstanceState. If yes, that means the onCreate was probably triggered by a configuration change *like screen rotate etc. If that's the case then populate all the views that are necessary here */ if (savedInstanceState != null) { ArrayList<BluetoothDevice> list = savedInstanceState.getParcelableArrayList(DEVICE_LIST); if (list != null) { initList(list); MyAdapter adapter = (MyAdapter) mLstDevices.getAdapter(); int selectedIndex = savedInstanceState.getInt(DEVICE_LIST_SELECTED); if (selectedIndex != -1) { adapter.setSelectedIndex(selectedIndex); mBtnConnect.setEnabled(true); } } else { initList(new ArrayList<BluetoothDevice>()); } } else { initList(new ArrayList<BluetoothDevice>()); } //IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); //this.registerReceiver(mReceiver, filter); // Register for broadcasts when discovery has finished //filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); //this.registerReceiver(mReceiver, filter); mBtnSearch.setOnClickListener(new OnClickListener() { List<BluetoothDevice> listDevices; @Override public void onClick(View arg0) { mBTAdapter = BluetoothAdapter.getDefaultAdapter(); heading.setText("Searching"); mBtnSearch.setEnabled(false); if (mBTAdapter == null) { Toast.makeText(getApplicationContext(), "Bluetooth not found", Toast.LENGTH_SHORT).show(); } else if (!mBTAdapter.isEnabled()) { Intent enableBT = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBT, BT_ENABLE_REQUEST); } else { //listDevices = new ArrayList<BluetoothDevice>(); /*for (BluetoothDevice device : pairedDevices) { listDevices.add(device); }*/ new SearchDevices().execute(); } } }); mButtonIbu.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if (mLstDevices != null) { ArrayList<BluetoothDevice> devices = (ArrayList<BluetoothDevice>) ((MyAdapter) (mLstDevices .getAdapter())).getEntireList(); Intent intent = new Intent(getApplicationContext(), MainActivity.class); intent.putExtra(DEVICES_LISTS, devices); try { } catch (NullPointerException ex) { } intent.putExtra(DEVICE_UUID, mDeviceUUID.toString()); intent.putExtra(BUFFER_SIZE, mBufferSize); startActivity(intent); } } }); mBtnConnect.setOnClickListener(new OnClickListener() { /** * connect to all paired devices */ @Override public void onClick(View arg0) { List<BluetoothDevice> devices = ((MyAdapter) (mLstDevices.getAdapter())).getEntireList(); for (int i = 0; i < devices.size(); i++) { BluetoothDevice device = devices.get(i); msg(device.getName()); Intent intent = new Intent(getApplicationContext(), MainActivity.class); intent.putExtra(DEVICE_EXTRA, device); intent.putExtra(DEVICE_UUID, mDeviceUUID.toString()); intent.putExtra(BUFFER_SIZE, mBufferSize); startActivity(intent); } } }); }
From source file:com.google.android.gcm.demo.app.BluetoothHDPActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Check for Bluetooth availability on the Android platform. mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter == null) { Toast.makeText(this, R.string.bluetooth_not_available, Toast.LENGTH_LONG); finish();/* w w w . j ava 2 s . c o m*/ return; } setContentView(R.layout.console); mConnectIndicator = (TextView) findViewById(R.id.connect_ind); mStatusMessage = (TextView) findViewById(R.id.status_msg); mResultMessage = (TextView) findViewById(R.id.result_msg); mDataIndicator = (ImageView) findViewById(R.id.data_ind); mRes = getResources(); mHealthServiceBound = false; // Initiates application registration through {@link BluetoothHDPService}. Button registerAppButton = (Button) findViewById(R.id.button_register_app); registerAppButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { sendMessage(BluetoothHDPService.MSG_REG_HEALTH_APP, HEALTH_PROFILE_SOURCE_DATA_TYPE); Log.d(TAG, "register button pressed"); } }); // Initiates application unregistration through {@link BluetoothHDPService}. Button unregisterAppButton = (Button) findViewById(R.id.button_unregister_app); unregisterAppButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { sendMessage(BluetoothHDPService.MSG_UNREG_HEALTH_APP, 0); Log.d(TAG, "unregister button pressed"); } }); // Initiates channel creation through {@link BluetoothHDPService}. Some devices will // initiate the channel connection, in which case, it is not necessary to do this in the // application. When pressed, the user is asked to select from one of the bonded devices // to connect to. Button connectButton = (Button) findViewById(R.id.button_connect_channel); connectButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Log.d(TAG, "clickConnect1"); mAllBondedDevices = (BluetoothDevice[]) mBluetoothAdapter.getBondedDevices() .toArray(new BluetoothDevice[0]); Log.d(TAG, "clickConnect2"); if (mAllBondedDevices.length > 0) { int deviceCount = mAllBondedDevices.length; if (mDeviceIndex < deviceCount) mDevice = mAllBondedDevices[mDeviceIndex]; else { mDeviceIndex = 0; mDevice = mAllBondedDevices[0]; } String[] deviceNames = new String[deviceCount]; int i = 0; for (BluetoothDevice device : mAllBondedDevices) { deviceNames[i++] = device.getName(); } SelectDeviceDialogFragment deviceDialog = SelectDeviceDialogFragment.newInstance(deviceNames, mDeviceIndex); deviceDialog.show(getFragmentManager(), "deviceDialog"); //sendMessage(BluetoothHDPService.MSG_CONNECT_CHANNEL, 0); //######### Log.d(TAG, "connect channel #####"); } } }); // Initiates channel disconnect through {@link BluetoothHDPService}. Button disconnectButton = (Button) findViewById(R.id.button_disconnect_channel); disconnectButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { disconnectChannel(); } }); registerReceiver(mReceiver, initIntentFilter()); }
From source file:com.github.akinaru.roboticbuttonpusher.bluetooth.BluetoothCustomManager.java
@SuppressLint("NewApi") public void init(Context context) { // Initializes Bluetooth adapter. final BluetoothManager bluetoothManager = (BluetoothManager) context .getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); //init message handler mHandler = null;/*from ww w. j av a2s . co m*/ mHandler = new Handler(); scanCallback = new BluetoothAdapter.LeScanCallback() { @Override public void onLeScan(BluetoothDevice device, int rssi, final byte[] scanRecord) { if (device.getAddress() != null && device.getName() != null) { dispatchBtDevices(device, rssi, scanRecord); } } }; }
From source file:com.wolkabout.hexiwear.service.BluetoothService.java
public void startReading(BluetoothDevice device) { Log.i(TAG, "Starting to read data for device: " + device.getName()); hexiwearDevice = hexiwearDevices.getDevice(device.getAddress()); bluetoothDevice = device;// w w w .jav a2s.co m createGATT(device); if (credentials.username().get().equals("Demo")) { return; } wolk = new Wolk(hexiwearDevice); wolk.setLogger(new Logger() { @Override public void info(final String message) { Log.i(TAG, message); } @Override public void error(final String message, final Throwable e) { Log.e(TAG, message, e); } }); if (hexiwearDevices.shouldTransmit(device)) { final int publishInterval = hexiwearDevices.getPublishInterval(hexiwearDevice); wolk.startAutoPublishing(publishInterval); } }
From source file:com.mattprecious.notisync.service.PrimaryService.java
private Notification buildRunningNotification(boolean nullIfNoChange) { Bundle notificationBundle = new Bundle(); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setPriority(NotificationCompat.PRIORITY_MIN); builder.setSmallIcon(R.drawable.ic_stat_logo); builder.setContentTitle(getString(R.string.app_name)); Intent intent = new Intent(this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); builder.setContentIntent(pendingIntent); String contentText = null;/*from w ww . ja va2 s . com*/ Set<String> connectedNames = Sets.newHashSet(); if (bluetoothAdapter.isEnabled()) { synchronized (bluetoothServices) { for (String address : bluetoothServices.keySet()) { BluetoothService service = bluetoothServices.get(address); if (service != null && service.getState() == BluetoothService.STATE_CONNECTED) { BluetoothDevice device = bluetoothAdapter.getRemoteDevice(address); connectedNames.add(device.getName()); } } } if (connectedNames.size() != Preferences.getDevices(this).size()) { PendingIntent reconnectIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_RECONNECT), 0); builder.addAction(R.drawable.ic_action_refresh, getString(R.string.noti_action_connect), reconnectIntent); notificationBundle.putBoolean("connect_action", true); } if (connectedNames.size() > 0) { contentText = getString(R.string.noti_connected_to, notificationJoiner.join(connectedNames)); } else { contentText = getString(R.string.noti_not_connected); } } else { contentText = getString(R.string.noti_bt_not_enabled); PendingIntent bluetoothIntent = PendingIntent.getActivity(this, 0, new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE), 0); builder.addAction(R.drawable.ic_action_bluetooth, getString(R.string.noti_action_enable_bt), bluetoothIntent); notificationBundle.putBoolean("bt_enable_action", true); } builder.setContentText(contentText); notificationBundle.putString("text", contentText); if (nullIfNoChange && bundleEquals(notificationBundle, lastNotificationBundle)) { return null; } lastNotificationBundle = notificationBundle; return builder.build(); }
From source file:com.github.akinaru.bleanalyzer.bluetooth.BluetoothCustomManager.java
@SuppressLint("NewApi") public void init(Context context) { // Initializes Bluetooth adapter. final BluetoothManager bluetoothManager = (BluetoothManager) context .getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); //init message handler mHandler = null;//w w w.j av a 2s.co m mHandler = new Handler(); scanCallback = new BluetoothAdapter.LeScanCallback() { @Override public void onLeScan(BluetoothDevice device, int rssi, final byte[] scanRecord) { if (device.getAddress() != null && device.getName() != null) { if (device.getName().equals("RFdroid")) { dispatchRFdroid(device, rssi, scanRecord); } else { dispatchBtDevices(device, rssi, scanRecord); } } } }; }
From source file:com.bluetooth.comp529.bluetoothchatproj.chat.BluetoothChatFragment.java
/** * Establish connection with other divice * * @param data An {@link Intent} with {@link DeviceListActivity#EXTRA_DEVICE_ADDRESS} extra. * @param secure Socket Security type - Secure (true) , Insecure (false) */// ww w . j a v a 2 s. c o m private void connectDevice(Intent data, boolean secure) { // Get the device MAC address String address = data.getExtras().getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS); // Get the BluetoothDevice object BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address); // save the address of this newly connected device mAllConnectedDevicesAddress.add(address); // Attempt to connect to the device Log.i(TAG, "BEGIN connecting to:" + device.getName()); mChatService.connect(device, secure); }