本文整理汇总了Java中android.bluetooth.BluetoothAdapter.getBondedDevices方法的典型用法代码示例。如果您正苦于以下问题:Java BluetoothAdapter.getBondedDevices方法的具体用法?Java BluetoothAdapter.getBondedDevices怎么用?Java BluetoothAdapter.getBondedDevices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.bluetooth.BluetoothAdapter
的用法示例。
在下文中一共展示了BluetoothAdapter.getBondedDevices方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findBluetoothDevice
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
void findBluetoothDevice(BluetoothAdapter myBluetoothAdapter,
String filter) {
Log.d(TAG, "(*) Initialising Bluetooth connection for device: " + filter);
if(myBluetoothAdapter.isEnabled()) {
for (BluetoothDevice pairedDevice : myBluetoothAdapter.getBondedDevices()) {
if (pairedDevice.getName().contains(filter /*Like MI*/)) {
Log.d(TAG, "\tDevice Name: " + pairedDevice.getName());
Log.d(TAG, "\tDevice MAC: " + pairedDevice.getAddress());
activeDevice = pairedDevice;
break;
}
}
}
Log.d(TAG, "\tDidnt find any device!");
}
示例2: writeToEntropyPool
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
@Override
protected void writeToEntropyPool(DataOutputStream out) throws IOException {
super.writeToEntropyPool(out);
out.writeInt(android.os.Process.myPid());
out.writeInt(android.os.Process.myTid());
out.writeInt(android.os.Process.myUid());
if (Build.FINGERPRINT != null) out.writeUTF(Build.FINGERPRINT);
if (Build.SERIAL != null) out.writeUTF(Build.SERIAL);
ContentResolver contentResolver = appContext.getContentResolver();
String id = Settings.Secure.getString(contentResolver, ANDROID_ID);
if (id != null) out.writeUTF(id);
Parcel parcel = Parcel.obtain();
WifiManager wm =
(WifiManager) appContext.getSystemService(WIFI_SERVICE);
List<WifiConfiguration> configs = wm.getConfiguredNetworks();
if (configs != null) {
for (WifiConfiguration config : configs)
parcel.writeParcelable(config, 0);
}
BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
if (bt != null) {
for (BluetoothDevice device : bt.getBondedDevices())
parcel.writeParcelable(device, 0);
}
out.write(parcel.marshall());
parcel.recycle();
}
示例3: logBluetoothAdapterInfo
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
/**
* Logs the state of the local Bluetooth adapter.
*/
@SuppressLint("HardwareIds")
protected void logBluetoothAdapterInfo(BluetoothAdapter localAdapter) {
Log.d(TAG, "BluetoothAdapter: "
+ "enabled=" + localAdapter.isEnabled() + ", "
+ "state=" + stateToString(localAdapter.getState()) + ", "
+ "name=" + localAdapter.getName() + ", "
+ "address=" + localAdapter.getAddress());
// Log the set of BluetoothDevice objects that are bonded (paired) to the local adapter.
Set<BluetoothDevice> pairedDevices = localAdapter.getBondedDevices();
if (!pairedDevices.isEmpty()) {
Log.d(TAG, "paired devices:");
for (BluetoothDevice device : pairedDevices) {
Log.d(TAG, " name=" + device.getName() + ", address=" + device.getAddress());
}
}
}
示例4: onCreateDialog
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
final List<BluetoothDevice> bondedDevices = new ArrayList<>(btAdapter.getBondedDevices());
String[] boundedDeviceNames = new String[bondedDevices.size()];
for (int i = 0; i < bondedDevices.size(); i++) {
boundedDeviceNames[i] = bondedDevices.get(i).getName();
}
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.choose_bt_device)
.setCancelable(false)
.setItems(boundedDeviceNames, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
BluetoothDevice bluetoothDevice = bondedDevices.get(which);
listener.onDeviceChoose(bluetoothDevice);
}
});
return builder.create();
}
示例5: logBluetoothAdapterInfo
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
/** Logs the state of the local Bluetooth adapter. */
@SuppressLint("HardwareIds")
protected void logBluetoothAdapterInfo(BluetoothAdapter localAdapter) {
Log.d(TAG, "BluetoothAdapter: "
+ "enabled=" + localAdapter.isEnabled() + ", "
+ "state=" + stateToString(localAdapter.getState()) + ", "
+ "name=" + localAdapter.getName() + ", "
+ "address=" + localAdapter.getAddress());
// Log the set of BluetoothDevice objects that are bonded (paired) to the local adapter.
Set<BluetoothDevice> pairedDevices = localAdapter.getBondedDevices();
if (!pairedDevices.isEmpty()) {
Log.d(TAG, "paired devices:");
for (BluetoothDevice device : pairedDevices) {
Log.d(TAG, " name=" + device.getName() + ", address=" + device.getAddress());
}
}
}
示例6: unPairDevice
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
/**
* Finds all bonded devices and tries to unbond it.
*/
private void unPairDevice() {
ConnectedDevice connectedDevice = BluetoothUtils.getPairedMicrobit(this);
String addressToDelete = connectedDevice.mAddress;
// Get the paired devices and put them in a Set
BluetoothAdapter mBluetoothAdapter = ((BluetoothManager) getSystemService(BLUETOOTH_SERVICE)).getAdapter();
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
for(BluetoothDevice bt : pairedDevices) {
logi("Paired device " + bt.getName());
if(bt.getAddress().equals(addressToDelete)) {
try {
Method m = bt.getClass().getMethod("removeBond", (Class[]) null);
m.invoke(bt, (Object[]) null);
} catch(NoSuchMethodException | IllegalAccessException
| InvocationTargetException e) {
Log.e(TAG, e.toString());
}
}
}
}
示例7: getPairedDeviceMicroBit
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
public static BluetoothDevice getPairedDeviceMicroBit(Context context) {
SharedPreferences pairedDevicePref = context.getApplicationContext().getSharedPreferences(PREFERENCES_KEY,
Context.MODE_MULTI_PROCESS);
if(pairedDevicePref.contains(PREFERENCES_PAIREDDEV_KEY)) {
String pairedDeviceString = pairedDevicePref.getString(PREFERENCES_PAIREDDEV_KEY, null);
Gson gson = new Gson();
sConnectedDevice = gson.fromJson(pairedDeviceString, ConnectedDevice.class);
//Check if the microbit is still paired with our mobile
BluetoothAdapter mBluetoothAdapter = ((BluetoothManager) MBApp.getApp().getSystemService(Context
.BLUETOOTH_SERVICE)).getAdapter();
if(mBluetoothAdapter.isEnabled()) {
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
for(BluetoothDevice bt : pairedDevices) {
if(bt.getAddress().equals(sConnectedDevice.mAddress)) {
return bt;
}
}
}
}
return null;
}
示例8: logBluetoothAdapterInfo
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
/**
* Logs the state of the local Bluetooth adapter.
*/
protected void logBluetoothAdapterInfo(BluetoothAdapter localAdapter) {
Log.d(TAG, "BluetoothAdapter: "
+ "enabled=" + localAdapter.isEnabled() + ", "
+ "state=" + stateToString(localAdapter.getState()) + ", "
+ "name=" + localAdapter.getName() + ", "
+ "address=" + localAdapter.getAddress());
// Log the set of BluetoothDevice objects that are bonded (paired) to the local adapter.
Set<BluetoothDevice> pairedDevices = localAdapter.getBondedDevices();
if (!pairedDevices.isEmpty()) {
Log.d(TAG, "paired devices:");
for (BluetoothDevice device : pairedDevices) {
Log.d(TAG, " name=" + device.getName() + ", address=" + device.getAddress());
}
}
}
示例9: onCreateView
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
View view = inflater.inflate(R.layout.view_add_bluetooth_server, container);
ListView listViewBtPairedPCs = (ListView) view.findViewById(R.id.listViewBtPairedPCs);
ArrayList<BluetoothDevice> pairedBluetoothList = new ArrayList<>();
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
if (pairedDevices.size() > 0) {
for (BluetoothDevice device : pairedDevices) {
if(device.getBluetoothClass().getMajorDeviceClass() == BluetoothClass.Device.Major.COMPUTER) {
pairedBluetoothList.add(device);
}
}
if (pairedBluetoothList.size() == 0) {
Toast.makeText(getActivity().getApplicationContext(), R.string.bluetooth_no_paired_found, Toast.LENGTH_LONG).show();
return null;
}
} else {
Toast.makeText(getActivity().getApplicationContext(), R.string.bluetooth_no_paired_found, Toast.LENGTH_LONG).show();
return null;
}
BluetoothPairedDevicesAdapter adapter = new BluetoothPairedDevicesAdapter(getActivity(), pairedBluetoothList, this);
listViewBtPairedPCs.setAdapter(adapter);
return view;
}
示例10: getDevice
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
public static BluetoothDevice getDevice(BluetoothAdapter bluetoothAdapter) {
BluetoothDevice innerprinter_device = null;
Set<BluetoothDevice> devices = bluetoothAdapter.getBondedDevices();
for (BluetoothDevice device : devices) {
if (device.getAddress().equals(Innerprinter_Address)) {
innerprinter_device = device;
break;
}
}
return innerprinter_device;
}
示例11: getTotalPairedMicroBitsFromSystem
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
public static int getTotalPairedMicroBitsFromSystem() {
int totalPairedMicroBits = 0;
BluetoothAdapter mBluetoothAdapter = ((BluetoothManager) MBApp.getApp().getSystemService(Context
.BLUETOOTH_SERVICE)).getAdapter();
if(mBluetoothAdapter != null && !mBluetoothAdapter.isEnabled()) {
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
for(BluetoothDevice bt : pairedDevices) {
if(bt.getName().contains("micro:bit")) {
++totalPairedMicroBits;
}
}
}
return totalPairedMicroBits;
}
示例12: onStartConnection
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
@Override
public int onStartConnection() {
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
BluetoothDevice bioharness = null;
int replyCode;
if (bluetoothAdapter == null) {
replyCode = PHONE_NO_BLUETOOTH;
} else if (!bluetoothAdapter.isEnabled()) {
replyCode = BLUETOOTH_NOT_ACTIVE;
} else {
Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
if (pairedDevices.size() > 0) {
for (BluetoothDevice device : pairedDevices) {
if (device.getName().startsWith("BH")) {
bioharness = device;
}
}
}
if (bioharness == null) {
replyCode = BIOHARNESS_NOT_PAIRED;
} else {
replyCode = BIOHARNESS_PAIRED;
if (btc != null) {
replyCode = BIOHARNESS_ALREADY_CONNECTED;
} else {
boolean result = connect(bioharness);
if (result) {
replyCode = BIOHARNESS_CONNECTED;
connectToAgentEnvironment();
}
}
}
}
return replyCode;
}
示例13: BTinit
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
public boolean BTinit() {
boolean found = false;
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null) {
Toast.makeText(getApplicationContext(), "Device doesnt Support Bluetooth", Toast.LENGTH_SHORT).show();
}
if (!bluetoothAdapter.isEnabled()) {
Intent enableAdapter = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableAdapter, 0);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Set<BluetoothDevice> bondedDevices = bluetoothAdapter.getBondedDevices();
if (bondedDevices.isEmpty()) {
Toast.makeText(getApplicationContext(), "Please Pair the Device first", Toast.LENGTH_SHORT).show();
} else {
for (BluetoothDevice iterator : bondedDevices) {
if (iterator.getAddress().equals(DEVICE_ADDRESS)) {
device = iterator;
found = true;
break;
}
}
}
return found;
}
示例14: connect
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
/**
* connect the zephyr device and set Connection event listener
*
* @param deviceInfo the device info
* @param mBluetoothAdapter the m bluetooth adapter
* @throws DeviceConnectException the device connect exception
*/
public void connect(DeviceInfoBean deviceInfo, BluetoothAdapter mBluetoothAdapter) throws DeviceConnectException {
this.mDeviceInfo = deviceInfo;
/**
* checking for the paired devices
*/
for (BluetoothDevice pairedDevice : mBluetoothAdapter.getBondedDevices()) {
if (pairedDevice.getAddress().startsWith(deviceInfo.getDevice_udi())) {
mBTClient = new BTClient(mBluetoothAdapter, deviceInfo.getDevice_udi());
mZephyrConnectionListener = new ZephyrConnectListener(mHandler, mHandler);
mBTClient.addConnectedEventListener(mZephyrConnectionListener);
if (mBTClient.IsConnected()) {
mReceiver.isConnected(true);
HealthCareApp healthCareApp = (HealthCareApp) ((Activity) mContext).getApplication();
healthCareApp.startPostDataService();
break;
}
mBTClient = null;
}
}
if (mBTClient == null)
throw new DeviceConnectException(mContext.getString(R.string.no_device_found));
mBTClient.start();
}
示例15: initConnection
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
public boolean initConnection(){
boolean Devicefound = false;
BluetoothAdapter _BluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if(_BluetoothAdapter == null){
Toast.makeText(getApplicationContext(),"Device doesnt Support Bluetooth ! ", Toast.LENGTH_SHORT).show();
}
else {
if(!_BluetoothAdapter.isEnabled()){
Intent enable = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enable , 0);
try{
Thread.sleep(1000);
}
catch(Exception e){
e.printStackTrace();
}
}
Set<BluetoothDevice> BluetoothDevices = _BluetoothAdapter.getBondedDevices();
if(BluetoothDevices.isEmpty()){
Toast.makeText(getApplicationContext(),"come on the Device isn't even paired ! ",Toast.LENGTH_SHORT).show();
}
else {
for(BluetoothDevice _BluetoothDevice : BluetoothDevices){
if(_BluetoothDevice.getAddress().equals(DeviceAddress)){
device = _BluetoothDevice;
Devicefound = true;
Toast.makeText(getApplicationContext(),"Connected to the required device", Toast.LENGTH_SHORT).show();
}
if(_BluetoothDevice.getAddress().equals(DeviceAddress)){
device = _BluetoothDevice;
Devicefound = true;
}
}
}
}
return Devicefound;
}