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


Java BluetoothAdapter.isEnabled方法代码示例

本文整理汇总了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();
        }
    }
}
 
开发者ID:poletalks,项目名称:Pole-Beacon-Android-SDK,代码行数:19,代码来源:MainActivity.java

示例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;
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:22,代码来源:BluetoothUtils.java

示例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();
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:26,代码来源:ShowQrCodeFragment.java

示例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();
}
 
开发者ID:holgi-s,项目名称:RangeThings,代码行数:26,代码来源:GattServer.java

示例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();
    }
}
 
开发者ID:Nilhcem,项目名称:blefun-androidthings,代码行数:23,代码来源:GattServer.java

示例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();
    }
}
 
开发者ID:Nilhcem,项目名称:blefun-androidthings,代码行数:22,代码来源:ScanActivity.java

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

示例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();
}
 
开发者ID:kevalpatel2106,项目名称:robo-car,代码行数:10,代码来源:Beacon.java

示例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;
}
 
开发者ID:GuepardoApps,项目名称:LucaHome-AndroidApplication,代码行数:11,代码来源:BluetoothController.java

示例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();
    }
  }
}
 
开发者ID:tkrworks,项目名称:JinsMemeBRIDGE-Android,代码行数:15,代码来源:MainActivity.java

示例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;
}
 
开发者ID:amraboelkher,项目名称:Flame-Detector-RC-Car,代码行数:40,代码来源:Bluetooth.java

示例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;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:9,代码来源:Utils.java

示例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;
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:15,代码来源:BluetoothUtils.java

示例14: onDestroy

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
public void onDestroy() {
    mListener = null;

    BluetoothAdapter bluetoothAdapter = mBluetoothManager.getAdapter();
    if (bluetoothAdapter.isEnabled()) {
        stopClient();
    }

    mContext.unregisterReceiver(mBluetoothReceiver);
}
 
开发者ID:Nilhcem,项目名称:blefun-androidthings,代码行数:11,代码来源:GattClient.java

示例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);
}
 
开发者ID:kshoji,项目名称:BLE-HID-Peripheral-for-Android,代码行数:74,代码来源:HidPeripheral.java


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