本文整理汇总了Java中android.bluetooth.BluetoothAdapter.isEnabled方法的典型用法代码示例。如果您正苦于以下问题:Java BluetoothAdapter.isEnabled方法的具体用法?Java BluetoothAdapter.isEnabled怎么用?Java BluetoothAdapter.isEnabled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.bluetooth.BluetoothAdapter
的用法示例。
在下文中一共展示了BluetoothAdapter.isEnabled方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_pole_sdk);
PoleProximityManager.onCreateBeacons(this, null);
context = this;
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter != null) {
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
} else {
PoleProximityManager.startScanning();
}
}
}
示例2: 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;
}
示例3: onStart
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
@Override
public void onStart() {
super.onStart();
// Listen for changes to the Bluetooth state
IntentFilter filter = new IntentFilter();
filter.addAction(ACTION_STATE_CHANGED);
receiver = new BluetoothStateReceiver();
getActivity().registerReceiver(receiver, filter);
// Enable BT adapter if it is not already on.
final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null && !adapter.isEnabled()) {
waitingForBluetooth = true;
androidExecutor.runOnBackgroundThread(new Runnable() {
@Override
public void run() {
adapter.enable();
}
});
} else {
startListening();
}
cameraView.start();
}
示例4: checkBluetooth
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
static public boolean checkBluetooth(Context context){
BluetoothManager bm = (BluetoothManager) context.getSystemService(BLUETOOTH_SERVICE);
BluetoothAdapter ba = bm.getAdapter();
if (ba == null) {
//Bluetooth is disabled
Log.e(TAG, "BluetoothAdapter not available!");
return false;
}
if(!ba.isEnabled()) {
Log.w(TAG, "BluetoothAdapter not enabled!");
ba.enable();
}
if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
Log.e(TAG, "Bluetooth LE is not supported");
return false;
}
if(!ba.isMultipleAdvertisementSupported()){
Log.i(TAG, "No Multiple Advertisement Support!");
}
return ba.isEnabled();
}
示例5: onCreate
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
public void onCreate(Context context, GattServerListener listener) throws RuntimeException {
mContext = context;
mListener = listener;
mBluetoothManager = (BluetoothManager) context.getSystemService(BLUETOOTH_SERVICE);
BluetoothAdapter bluetoothAdapter = mBluetoothManager.getAdapter();
if (!checkBluetoothSupport(bluetoothAdapter)) {
throw new RuntimeException("GATT server requires Bluetooth support");
}
// Register for system Bluetooth events
IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
mContext.registerReceiver(mBluetoothReceiver, filter);
if (!bluetoothAdapter.isEnabled()) {
Log.d(TAG, "Bluetooth is currently disabled... enabling");
bluetoothAdapter.enable();
} else {
Log.d(TAG, "Bluetooth enabled... starting services");
startAdvertising();
startServer();
}
}
示例6: prepareForScan
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
private void prepareForScan() {
if (isBleSupported()) {
// Ensures Bluetooth is enabled on the device
BluetoothManager btManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter btAdapter = btManager.getAdapter();
if (btAdapter.isEnabled()) {
// Prompt for runtime permission
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
startLeScan();
} else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_PERMISSION_LOCATION);
}
} else {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
} else {
Toast.makeText(this, "BLE is not supported", Toast.LENGTH_LONG).show();
finish();
}
}
示例7: provide
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
@Override
protected void provide() {
BluetoothAdapter BTAdapter = BluetoothAdapter.getDefaultAdapter(); // Set up the adaptor
if (BTAdapter == null || !BTAdapter.isEnabled()) {
this.finish();
return;
}
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(android.bluetooth.BluetoothDevice.ACTION_FOUND);
intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
getContext().registerReceiver(mReceiver, intentFilter);
BTAdapter.startDiscovery();
}
示例8: enableBluetooth
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
/**
* Turn on the bluetooth if it is not already turned on.
*/
private void enableBluetooth() {
BluetoothAdapter adapter = ((BluetoothManager) mContext
.getSystemService(Context.BLUETOOTH_SERVICE))
.getAdapter();
if (!adapter.isEnabled()) adapter.enable();
}
示例9: IsBluetoothEnabled
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
public boolean IsBluetoothEnabled() {
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter != null) {
boolean isEnabled = bluetoothAdapter.isEnabled();
Logger.getInstance().Debug(TAG, String.format(Locale.getDefault(), "IsBluetoothEnabled: %s", isEnabled));
return isEnabled;
}
Logger.getInstance().Warning(TAG, "bluetoothAdapter is null!");
return false;
}
示例10: checkBluetoothEnable
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
private void checkBluetoothEnable() {
if (!isMemeConnected()) {
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter != null && !bluetoothAdapter.isEnabled()) {
Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(intent, 0);
} else if (bluetoothAdapter != null && bluetoothAdapter.isEnabled()) {
Log.d("DEBUG", "MAIN:: Initialize MEME LIB");
initMemeLib();
scanAndConnectToLastConnectedMeme();
}
}
}
示例11: 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;
}
示例12: getBluetoothEnabledStatus
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
public static int getBluetoothEnabledStatus() {
int statusResult = RESULT_INDETERMINATE;
if (isBluetoothPermissionGranted()) {
BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
statusResult = (bt != null && bt.isEnabled()) ? RESULT_SUCCESS : RESULT_FAILURE;
}
return statusResult;
}
示例13: 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;
}
示例14: onDestroy
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
public void onDestroy() {
mListener = null;
BluetoothAdapter bluetoothAdapter = mBluetoothManager.getAdapter();
if (bluetoothAdapter.isEnabled()) {
stopClient();
}
mContext.unregisterReceiver(mBluetoothReceiver);
}
示例15: HidPeripheral
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
/**
* Constructor<br />
* Before constructing the instance, check the Bluetooth availability.
*
* @param context the ApplicationContext
* @param needInputReport true: serves 'Input Report' BLE characteristic
* @param needOutputReport true: serves 'Output Report' BLE characteristic
* @param needFeatureReport true: serves 'Feature Report' BLE characteristic
* @param dataSendingRate sending rate in milliseconds
* @throws UnsupportedOperationException if starting Bluetooth LE Peripheral failed
*/
protected HidPeripheral(final Context context, final boolean needInputReport, final boolean needOutputReport, final boolean needFeatureReport, final int dataSendingRate) throws UnsupportedOperationException {
applicationContext = context.getApplicationContext();
handler = new Handler(applicationContext.getMainLooper());
final BluetoothManager bluetoothManager = (BluetoothManager) applicationContext.getSystemService(Context.BLUETOOTH_SERVICE);
final BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
if (bluetoothAdapter == null) {
throw new UnsupportedOperationException("Bluetooth is not available.");
}
if (!bluetoothAdapter.isEnabled()) {
throw new UnsupportedOperationException("Bluetooth is disabled.");
}
Log.d(TAG, "isMultipleAdvertisementSupported:" + bluetoothAdapter.isMultipleAdvertisementSupported());
if (!bluetoothAdapter.isMultipleAdvertisementSupported()) {
throw new UnsupportedOperationException("Bluetooth LE Advertising not supported on this device.");
}
bluetoothLeAdvertiser = bluetoothAdapter.getBluetoothLeAdvertiser();
Log.d(TAG, "bluetoothLeAdvertiser: " + bluetoothLeAdvertiser);
if (bluetoothLeAdvertiser == null) {
throw new UnsupportedOperationException("Bluetooth LE Advertising not supported on this device.");
}
gattServer = bluetoothManager.openGattServer(applicationContext, gattServerCallback);
if (gattServer == null) {
throw new UnsupportedOperationException("gattServer is null, check Bluetooth is ON.");
}
// setup services
addService(setUpHidService(needInputReport, needOutputReport, needFeatureReport));
addService(setUpDeviceInformationService());
addService(setUpBatteryService());
// send report each dataSendingRate, if data available
new Timer().scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
final byte[] polled = inputReportQueue.poll();
if (polled != null && inputReportCharacteristic != null) {
inputReportCharacteristic.setValue(polled);
handler.post(new Runnable() {
@Override
public void run() {
final Set<BluetoothDevice> devices = getDevices();
for (final BluetoothDevice device : devices) {
try {
if (gattServer != null) {
gattServer.notifyCharacteristicChanged(device, inputReportCharacteristic, false);
}
} catch (final Throwable ignored) {
}
}
}
});
}
}
}, 0, dataSendingRate);
}