• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java BluetoothAdapter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: openBtDevice

import android.bluetooth.BluetoothAdapter; //导入依赖的package包/类
private boolean openBtDevice() {
        // 获得蓝牙匹配器
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        // 蓝牙设备不被支持
        if (mBluetoothAdapter == null) {
            Toast.makeText(getActivity(), "该设备没有蓝牙设备", Toast.LENGTH_LONG).show();
            return false;
        }

        // 蓝牙如果没打开,直接提示需要打开蓝牙
        if (!mBluetoothAdapter.isEnabled()) {
            // 隐式Intent
            Intent enableBtIntent = new Intent(
                    BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(enableBtIntent, REQUES_BT_ENABLE_CODE);  //在onActivityResult有打开服务端线程的操作哦
        } else {
            // 如果蓝牙在运行本程序前已经人为打开,那么直接启动服务器端线程
            Toast.makeText(getActivity(), "蓝牙已经打开!	", Toast.LENGTH_LONG).show();
            //暂时不启动服务端线程,因为手机充当的总是客服端
//            mAcceptThread = new AcceptThread(mBluetoothAdapter,mHandler); // // // // // // // // // // // // // // // // // // // // // // // // //
//            mAcceptThread.start(); // // // // // // // // // // // // // // // //蓝牙提前打开就启动服务端线程? // // // // // //
        }
        return true;
    }
 
开发者ID:fergus825,项目名称:SmartOrnament,代码行数:25,代码来源:LinkDeviceFragment.java


示例17: onReceive

import android.bluetooth.BluetoothAdapter; //导入依赖的package包/类
public void onReceive(Context context, Intent intent)
{
	String action = intent.getAction();
	
	if (action.equals(BluetoothDevice.ACTION_FOUND))
	{
		BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
		
		if (!BluetoothDevicesActivity.this.deviceList.contains(device))
		{
			BluetoothDevicesActivity.this.deviceList.add(device);
			BluetoothDevicesActivity.this.deviceListAdapter.notifyDataSetChanged();
		}
	}
	else if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_STARTED))
	{
		Toast.makeText(context, "Bluetooth discovery started", Toast.LENGTH_SHORT).show();

	}
	else if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED))
	{
		Toast.makeText(context, "Bluetooth discovery finished", Toast.LENGTH_SHORT).show();

	}
}
 
开发者ID:Elbehiry,项目名称:Pc-Control,代码行数:26,代码来源:BluetoothDevicesActivity.java


示例18: setupBLE

import android.bluetooth.BluetoothAdapter; //导入依赖的package包/类
private void setupBLE() {
    if (!isBLESupported(this)) {
        Toast.makeText(this, "device not support ble", Toast.LENGTH_SHORT).show();
        finish();
        return;
    }

    BluetoothManager manager = getManager(this);
    if (manager != null) {
        mBTAdapter = manager.getAdapter();
    }
    if ((mBTAdapter == null) || (!mBTAdapter.isEnabled())) {
        Toast.makeText(this, "bluetooth not open", Toast.LENGTH_SHORT).show();
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
        return;
    }
}
 
开发者ID:wooden-fishes,项目名称:IBeaconBroadcastDemo,代码行数:19,代码来源:MainActivity.java


示例19: onReceive

import android.bluetooth.BluetoothAdapter; //导入依赖的package包/类
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
        Log.d("BLUETOOTH", "DISCOVERY STARTED"); //lo que se ejecuta cuando el bluetooth comienza a escanear
    } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { //lo que se ejecuta cuando el bluetooth finaliza el escaneo
        Log.d("BLUETOOTH", "DISCOVERY FINISHED");

    } else if (BluetoothDevice.ACTION_FOUND.equals(action)) { //lo que se ejecuta cuando el bluetooth encuentra un dispositivo
        final BluetoothDevice device = (BluetoothDevice) intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        Log.d("BLUETOOTH", "DEVICE DISCOVERED");

        listaDevices.put(device.getAddress(), device);
        Bundle bundle = new Bundle();
        bundle.putString("address", device.getAddress());
        //TODO crear constantes para los codigos de envio
        resultReceiverListarYConectar.send(100, bundle);
        /*runOnUiThread(new Runnable() {
            @Override
            public void run() {
                list.add(device.getAddress());
                listaDevices.put(device.getAddress(), device);
                adapter.notifyDataSetChanged();
            }
        });*/
    }
}
 
开发者ID:TfgReconocimientoPulseras,项目名称:TrainAppTFG,代码行数:27,代码来源:BluetoothLeService.java


示例20: makeDiscoverable

import android.bluetooth.BluetoothAdapter; //导入依赖的package包/类
public void makeDiscoverable() {
    if (mBluetoothAdapter == null) {
        return;
    } else {
        if (mBluetoothAdapter.isEnabled() && isDiscoverable()) {
            Log.e("", "===> mBluetoothAdapter.isDiscoverable()");

            return;
        } else {
            Log.e("", "===> makeDiscoverable");

            Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
            discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, mTimeDiscoverable);
            mActivity.startActivityForResult(discoverableIntent, REQUEST_DISCOVERABLE_CODE);
        }
    }
}
 
开发者ID:n8fr8,项目名称:LittleBitLouder,代码行数:18,代码来源:BluetoothManager.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Injector类代码示例发布时间:2022-05-20
下一篇:
Java DeserializationFeature类代码示例发布时间:2022-05-20
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap