How to detect if android device is paired with android wear watch

前端 未结 5 900
忘了有多久
忘了有多久 2020-12-01 08:24

I am creating an android wear app that extends push notifications. My app downloads approximately 10 images from a server when a push notification comes in and displays the

5条回答
  •  感情败类
    2020-12-01 08:50

    Check for paired devices

    You can check that the user has a watch paired with his device while it doesn't has to be connected at the time. This is better as this way the watch does not have to be connected at the time to be detected.

    BluetoothAdapter mBtAdapter = BluetoothAdapter.getDefaultAdapter();
    
    Set pairedDevices = mBtAdapter.getBondedDevices();
    if (pairedDevices.size() > 0) {
        for (BluetoothDevice device : pairedDevices) {
            if(device.getDeviceClass()==BluetoothClass.Device.WEARABLE_WRIST_WATCH){
                Log.d("Found", "Paired wearable: "+ device.getName() + ", with address: " + device.getAddress());
            {
        {
    } else {
        Toast.makeText(this, "No paired wearables found", Toast.LENGTH_SHORT).show();
    }
    

    Note that this code requires bluetooth permissions in your manifest.

    
    
    

提交回复
热议问题