当前位置: 首页>>代码示例>>Java>>正文


Java BluetoothAdapter类代码示例

本文整理汇总了Java中android.bluetooth.BluetoothAdapter的典型用法代码示例。如果您正苦于以下问题:Java BluetoothAdapter类的具体用法?Java BluetoothAdapter怎么用?Java BluetoothAdapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BluetoothAdapter类属于android.bluetooth包,在下文中一共展示了BluetoothAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onReceive

import android.bluetooth.BluetoothAdapter; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    // When discovery finds a device
    if (BluetoothDevice.ACTION_FOUND.equals(action)) {
        // Get the BluetoothDevice object from the Intent
        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        // If it's already paired, skip it, because it's been listed already
        if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
            mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
        }
        // When discovery is finished, change the Activity title
    } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
        setProgressBarIndeterminateVisibility(false);
        setTitle(R.string.select_device);
        if (mNewDevicesArrayAdapter.getCount() == 0) {
            String noDevices = getResources().getText(R.string.none_found).toString();
            mNewDevicesArrayAdapter.add(noDevices);
        }
    }
}
 
开发者ID:haraldh,项目名称:iconsole-android,代码行数:23,代码来源:DeviceListActivity.java

示例2: sendFDroid

import android.bluetooth.BluetoothAdapter; //导入依赖的package包/类
public void sendFDroid() {
    // If Bluetooth has not been enabled/turned on, then enabling device discoverability
    // will automatically enable Bluetooth.
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter != null) {
        if (adapter.getState() != BluetoothAdapter.STATE_ON) {
            Intent discoverBt = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
            discoverBt.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 120);
            startActivityForResult(discoverBt, REQUEST_BLUETOOTH_ENABLE_FOR_SEND);
        } else {
            sendFDroidApk();
        }
    } else {
        new AlertDialog.Builder(this)
                .setTitle(R.string.bluetooth_unavailable)
                .setMessage(R.string.swap_cant_send_no_bluetooth)
                .setNegativeButton(
                        R.string.cancel,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) { }
                        }
                ).create().show();
    }
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:26,代码来源:SwapWorkflowActivity.java

示例3: connect

import android.bluetooth.BluetoothAdapter; //导入依赖的package包/类
@ReactMethod
public void connect(String peripheralUUID, Callback callback) {
	Log.d(LOG_TAG, "Connect to: " + peripheralUUID );

	synchronized(peripherals) {
		Peripheral peripheral = peripherals.get(peripheralUUID);
		Log.e(LOG_TAG, "peripheral " + peripheral);
		if (peripheral == null) {
			if (peripheralUUID != null) {
				peripheralUUID = peripheralUUID.toUpperCase();
			}
			if (BluetoothAdapter.checkBluetoothAddress(peripheralUUID)) {
				BluetoothDevice device = bluetoothAdapter.getRemoteDevice(peripheralUUID);
				peripheral = new Peripheral(device, reactContext);
				peripherals.put(peripheralUUID, peripheral);
			} else {
				callback.invoke("Invalid peripheral uuid");
				return;
			}
		}
		peripheral.connect(callback, reactContext!=null?getCurrentActivity():context);
	}
}
 
开发者ID:lenglengiOS,项目名称:react-native-blue-manager,代码行数:24,代码来源:BleManager.java

示例4: ensureInit

import android.bluetooth.BluetoothAdapter; //导入依赖的package包/类
private boolean ensureInit() {
	if (mBluetoothAdapter == null) {
		mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
	}
	if (mContext == null) {
		if (LinphoneService.isReady()) {
			mContext = LinphoneService.instance().getApplicationContext();
		} else {
			return false;
		}
	}
	if (mContext != null && mAudioManager == null) {
		mAudioManager = ((AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE));
	}
	return true;
}
 
开发者ID:treasure-lau,项目名称:Linphone4Android,代码行数:17,代码来源:BluetoothManager.java

示例5: BluetoothStateManager

import android.bluetooth.BluetoothAdapter; //导入依赖的package包/类
public BluetoothStateManager(@NonNull Context context, @Nullable BluetoothStateListener listener) {
  this.context                     = context.getApplicationContext();
  this.bluetoothAdapter            = BluetoothAdapter.getDefaultAdapter();
  this.bluetoothScoReceiver        = new BluetoothScoReceiver();
  this.bluetoothConnectionReceiver = new BluetoothConnectionReceiver();
  this.listener                    = listener;

  if (this.bluetoothAdapter == null)
    return;

  requestHeadsetProxyProfile();

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    context.registerReceiver(bluetoothConnectionReceiver, new IntentFilter(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED));
  }

  Intent sticky = context.registerReceiver(bluetoothScoReceiver, new IntentFilter(getScoChangeIntent()));

  if (sticky != null) {
    bluetoothScoReceiver.onReceive(context, sticky);
  }

  handleBluetoothStateChange();
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:25,代码来源:BluetoothStateManager.java

示例6: pairIntentFilter

import android.bluetooth.BluetoothAdapter; //导入依赖的package包/类
private static IntentFilter pairIntentFilter() {
        final IntentFilter intentFilter = new IntentFilter();
       /* reserved for other usages */
/*
        intentFilter.addAction(BluetoothDevice.ACTION_FOUND);
        intentFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
        intentFilter.addAction(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
        intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
        intentFilter.addAction(BluetoothDevice.ACTION_PAIRING_REQUEST);
        */
        intentFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
        intentFilter.addAction(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
        intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
        intentFilter.addAction(BluetoothDevice.ACTION_PAIRING_REQUEST);
        intentFilter.addAction("com.bluetooth.device.action.FOUND");
        intentFilter.setPriority(Integer.MAX_VALUE);

        return intentFilter;
    }
 
开发者ID:haoyifan,项目名称:BLE-PEPS,代码行数:20,代码来源:BleClientMainActivity.java

示例7: onResume

import android.bluetooth.BluetoothAdapter; //导入依赖的package包/类
@Override
public void onResume() {
    super.onResume();

    // Register ChipRobotFinder broadcast receiver
    this.getActivity().registerReceiver(mChipFinderBroadcastReceiver, ChipRobotFinder.getChipRobotFinderIntentFilter());

    // Ensures Bluetooth is enabled on the device.  If Bluetooth is not currently enabled,
    // fire an intent to display a dialog asking the user to grant permission to enable it.
    if (mBluetoothAdapter != null && !mBluetoothAdapter.isEnabled()) {
        if (!mBluetoothAdapter.isEnabled()) {
            try {
                Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);

            } catch (ActivityNotFoundException ex) {
            }
        }
    }

    // Start scan
    ChipRobotFinder.getInstance().clearFoundChipList();
    scanLeDevice(false);
    updateChipList();
    scanLeDevice(true);
}
 
开发者ID:WowWeeLabs,项目名称:CHIP-Android-SDK,代码行数:27,代码来源:ConnectFragment.java

示例8: connectToBluetooth

import android.bluetooth.BluetoothAdapter; //导入依赖的package包/类
/**
 * connect the device to bluetooth
 *
 * @param context    the context
 * @param deviceInfo the device info
 * @param receiver   the receiver
 * @throws DeviceConnectException the device connect exception
 */
public void connectToBluetooth(Context context, DeviceInfoBean deviceInfo, IHealthCareReceiver receiver) throws DeviceConnectException {
    isDeviceFound = false;
    iHealthCareReceiver = receiver;
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBluetoothAdapter == null) {
        throw new DeviceConnectException(mContext.getString(R.string.bluetooth_settings_problem));
    }

    mContext = context;
    mDeviceInfo = deviceInfo;
    IntentFilter filter = new IntentFilter();
    filter.addAction(BluetoothDevice.ACTION_FOUND);
    filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
    filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
    filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
    filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    mContext.getApplicationContext().registerReceiver(mReceiver, filter);

    if (mBluetoothAdapter.getState() != BluetoothAdapter.STATE_ON)
        throw new DeviceConnectException(mContext.getString(R.string.bluetooth_state_not_ready));

    mBluetoothAdapter.startDiscovery();
}
 
开发者ID:Welloculus,项目名称:MobileAppForPatient,代码行数:32,代码来源:BluetoothHandler.java

示例9: addStateListener

import android.bluetooth.BluetoothAdapter; //导入依赖的package包/类
private void addStateListener() {
    if (this.stateReceiver == null) {
        this.stateReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                onBluetoothStateChange(intent);
            }
        };
    }

    try {
        IntentFilter intentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
        webView.getContext().registerReceiver(this.stateReceiver, intentFilter);
    } catch (Exception e) {
        LOG.e(TAG, "Error registering state receiver: " + e.getMessage(), e);
    }
}
 
开发者ID:disit,项目名称:siiMobilityAppKit,代码行数:18,代码来源:BLECentralPlugin.java

示例10: handleClick

import android.bluetooth.BluetoothAdapter; //导入依赖的package包/类
@Override
public void handleClick() {
    if (mBluetoothEnableForTether)
        return;

    if (isTetheringOn()) {
        setTethering(false);
    } else {
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        if (adapter != null) {
            if (adapter.getState() == BluetoothAdapter.STATE_OFF) {
                mBluetoothEnableForTether = true;
                adapter.enable();
            } else if (adapter.getState() == BluetoothAdapter.STATE_ON) {
                setTethering(true);
            }
        }
    }
    refreshState();
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:21,代码来源:BluetoothTetheringTile.java

示例11: 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());
        }
    }
}
 
开发者ID:lgyjg,项目名称:AndroidRTC,代码行数:19,代码来源:AppRTCBluetoothManager.java

示例12: onReceive

import android.bluetooth.BluetoothAdapter; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    // When discovery finds a device
    if (BluetoothDevice.ACTION_FOUND.equals(action)) {
        // Get the BluetoothDevice object from the Intent
        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        // If it's already paired, skip it, because it's been listed already
        if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
            mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
        }
    // When discovery is finished, change the Activity title
    } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
        setProgressBarIndeterminateVisibility(false);
        setTitle(R.string.select_device);
        if (mNewDevicesArrayAdapter.getCount() == 0) {
            String noDevices = getResources().getText(R.string.none_found).toString();
            mNewDevicesArrayAdapter.add(noDevices);
        }
    }
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:23,代码来源:DeviceListActivity.java

示例13: onReceive

import android.bluetooth.BluetoothAdapter; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    switch (intent.getAction()) {
        case BluetoothAdapter.ACTION_STATE_CHANGED:
            int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
            switch (state) {
                case BluetoothAdapter.STATE_TURNING_ON:// 蓝牙打开中

                    break;
                case BluetoothAdapter.STATE_ON:// 蓝牙打开完成

                    break;
                case BluetoothAdapter.STATE_TURNING_OFF:// 蓝牙关闭中

                    break;
                case BluetoothAdapter.STATE_OFF:// 蓝牙关闭完成

                    break;
                default:
                    break;
            }
        default:
            break;
    }
}
 
开发者ID:RockyQu,项目名称:BluetoothKit,代码行数:26,代码来源:BluetoothReceiver.java

示例14: onCreate

import android.bluetooth.BluetoothAdapter; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if(D) Log.e(TAG, "+++ ON CREATE +++");

    // Set up the window layout
    setContentView(R.layout.main);

    // Get local Bluetooth adapter
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    // If the adapter is null, then Bluetooth is not supported
    if (mBluetoothAdapter == null) {
        Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        finish();
        return;
    }
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:19,代码来源:BluetoothChat.java

示例15: startAdvertising

import android.bluetooth.BluetoothAdapter; //导入依赖的package包/类
private void startAdvertising() {
    BluetoothAdapter bluetoothAdapter = mBluetoothManager.getAdapter();
    mBluetoothLeAdvertiser = bluetoothAdapter.getBluetoothLeAdvertiser();
    if (mBluetoothLeAdvertiser == null) {
        Log.w(TAG, "Failed to create advertiser");
        return;
    }

    AdvertiseSettings settings = new AdvertiseSettings.Builder()
            .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED)
            .setConnectable(true)
            .setTimeout(0)
            .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM)
            .build();

    AdvertiseData data = new AdvertiseData.Builder()
            .setIncludeDeviceName(true)
            .setIncludeTxPowerLevel(false)
            .addServiceUuid(new ParcelUuid(SERVICE_UUID))
            .build();

    mBluetoothLeAdvertiser
            .startAdvertising(settings, data, mAdvertiseCallback);
}
 
开发者ID:Nilhcem,项目名称:blefun-androidthings,代码行数:25,代码来源:GattServer.java


注:本文中的android.bluetooth.BluetoothAdapter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。