সঙ্গী ডিভাইস পেয়ারিং

Android 8.0 (API লেভেল 26) এবং তার উচ্চতর ভার্সনে চলা ডিভাইসগুলিতে, কম্প্যানিয়ন ডিভাইস পেয়ারিং আপনার অ্যাপের পক্ষ থেকে ACCESS_FINE_LOCATION অনুমতি ছাড়াই কাছাকাছি ডিভাইসগুলির ব্লুটুথ বা ওয়াই-ফাই স্ক্যান করে। এটি ব্যবহারকারীর গোপনীয়তা সুরক্ষা সর্বাধিক করতে সাহায্য করে। কম্প্যানিয়ন ডিভাইসের প্রাথমিক কনফিগারেশন সম্পাদন করতে এই পদ্ধতিটি ব্যবহার করুন, যেমন BLE-সক্ষম স্মার্ট ঘড়ি। এছাড়াও, কম্প্যানিয়ন ডিভাইস পেয়ারিংয়ের জন্য লোকেশন পরিষেবা সক্ষম করা প্রয়োজন।

কম্প্যানিয়ন ডিভাইস পেয়ারিং নিজে থেকে সংযোগ তৈরি করে না বা ক্রমাগত স্ক্যানিং সক্ষম করে না। অ্যাপগুলি সংযোগ স্থাপনের জন্য ব্লুটুথ বা ওয়াই-ফাই সংযোগ API ব্যবহার করতে পারে।

ডিভাইসটি পেয়ার করার পর, ডিভাইসটি ব্যাকগ্রাউন্ড থেকে অ্যাপটি শুরু করতে REQUEST_COMPANION_RUN_IN_BACKGROUND এবং REQUEST_COMPANION_USE_DATA_IN_BACKGROUND অনুমতি ব্যবহার করতে পারে। অ্যাপগুলি ব্যাকগ্রাউন্ড থেকে ফোরগ্রাউন্ড পরিষেবা শুরু করতে REQUEST_COMPANION_START_FOREGROUND_SERVICES_FROM_BACKGROUND অনুমতিও ব্যবহার করতে পারে।

একজন ব্যবহারকারী একটি তালিকা থেকে একটি ডিভাইস নির্বাচন করতে পারেন এবং অ্যাপটিকে ডিভাইস অ্যাক্সেস করার অনুমতি দিতে পারেন। আপনি যদি অ্যাপটি আনইনস্টল করেন বা disassociate() কল করেন তবে এই অনুমতিগুলি বাতিল করা হয়। ব্যবহারকারীর আর কোনও অ্যাসোসিয়েশনের প্রয়োজন না হলে, যেমন যখন তারা লগ আউট করে বা আবদ্ধ ডিভাইসগুলি সরিয়ে দেয়, তখন কম্প্যানিয়ন অ্যাপটি তার নিজস্ব অ্যাসোসিয়েশনগুলি সাফ করার জন্য দায়ী।

কম্প্যানিয়ন ডিভাইস পেয়ারিং বাস্তবায়ন করুন

এই বিভাগটি ব্যাখ্যা করে যে কীভাবে CompanionDeviceManager ব্যবহার করে আপনার অ্যাপটিকে Bluetooth, BLE এবং Wi-Fi এর মাধ্যমে কম্প্যানিয়ন ডিভাইসের সাথে যুক্ত করবেন।

কম্প্যানিয়ন ডিভাইসগুলি নির্দিষ্ট করুন

নিম্নলিখিত কোড নমুনাটি দেখায় কিভাবে একটি ম্যানিফেস্ট ফাইলে <uses-feature> ফ্ল্যাগ যোগ করতে হয়। এটি সিস্টেমকে বলে যে আপনার অ্যাপটি কম্প্যানিয়ন ডিভাইস সেট আপ করতে চায়।

<uses-feature android:name="android.software.companion_device_setup"/>

DeviceFilter অনুসারে ডিভাইসগুলির তালিকা তৈরি করুন

আপনার দেওয়া DeviceFilter সাথে মেলে এমন সমস্ত ইন-রেঞ্জ কম্প্যানিয়ন ডিভাইস আপনি প্রদর্শন করতে পারবেন (চিত্র ১-এ দেখানো হয়েছে)। যদি আপনি স্ক্যানিং শুধুমাত্র একটি ডিভাইসের মধ্যে সীমাবদ্ধ রাখতে চান, তাহলে আপনি setSingleDevice() true তে সেট করতে পারেন (চিত্র ২-এ দেখানো হয়েছে)।

কম্প্যানিয়ন ডিভাইস পেয়ারিং
চিত্র ১. কম্প্যানিয়ন ডিভাইস পেয়ারিং
একক ডিভাইস পেয়ারিং
চিত্র 2. একক ডিভাইস জোড়া

DeviceFilter এর সাবক্লাসগুলি নিম্নরূপ যা AssociationRequest এ নির্দিষ্ট করা যেতে পারে:

তিনটি সাবক্লাসেই এমন বিল্ডার রয়েছে যা ফিল্টারের কনফিগারেশনকে স্ট্রিমলাইন করে। নিম্নলিখিত উদাহরণে, একটি ডিভাইস একটি BluetoothDeviceFilter ব্যবহার করে একটি Bluetooth ডিভাইসের জন্য স্ক্যান করে।

কোটলিন

val deviceFilter: BluetoothDeviceFilter = BluetoothDeviceFilter.Builder()
        // Match only Bluetooth devices whose name matches the pattern.
        .setNamePattern(Pattern.compile("My device"))
        // Match only Bluetooth devices whose service UUID matches this pattern.
        .addServiceUuid(ParcelUuid(UUID(0x123abcL, -1L)), null)
        .build()

জাভা

BluetoothDeviceFilter deviceFilter = new BluetoothDeviceFilter.Builder()
        // Match only Bluetooth devices whose name matches the pattern.
        .setNamePattern(Pattern.compile("My device"))
        // Match only Bluetooth devices whose service UUID matches this pattern.
        .addServiceUuid(new ParcelUuid(new UUID(0x123abcL, -1L)), null)
        .build();

একটি DeviceFilter কে AssociationRequest এ সেট করুন যাতে CompanionDeviceManager কোন ধরণের ডিভাইস খুঁজতে হবে তা নির্ধারণ করতে পারে।

কোটলিন

val pairingRequest: AssociationRequest = AssociationRequest.Builder()
        // Find only devices that match this request filter.
        .addDeviceFilter(deviceFilter)
        // Stop scanning as soon as one device matching the filter is found.
        .setSingleDevice(true)
        .build()

জাভা

AssociationRequest pairingRequest = new AssociationRequest.Builder()
        // Find only devices that match this request filter.
        .addDeviceFilter(deviceFilter)
        // Stop scanning as soon as one device matching the filter is found.
        .setSingleDevice(true)
        .build();

আপনার অ্যাপটি AssociationRequest শুরু করার পরে, CompanionDeviceManagerassociate() ফাংশনটি চালান। associate() ফাংশনটি একটি AssociationRequest এবং একটি Callback গ্রহণ করে।

যখন CompanionDeviceManager কোনও ডিভাইস সনাক্ত করে এবং এটি ব্যবহারকারীর সম্মতি ডায়ালগ চালু করার জন্য প্রস্তুত হয়, তখন Callback onAssociationPending এ একটি IntentSender ফেরত পাঠায়। ব্যবহারকারী ডিভাইসটি নিশ্চিত করার পরে, onAssociationCreated এ ডিভাইসটির একটি AssociationInfo ফেরত পাঠানো হয়। যদি আপনার অ্যাপ কোনও ডিভাইস খুঁজে না পায়, তাহলে কলব্যাকটি একটি ত্রুটি বার্তা সহ onFailure ফেরত পাঠায়।

Android 13 (API লেভেল 33) এবং উচ্চতর ভার্সন চালিত ডিভাইসগুলিতে:

কোটলিন

val deviceManager =
  requireContext().getSystemService(Context.COMPANION_DEVICE_SERVICE)

val executor: Executor =  Executor { it.run() }

deviceManager.associate(pairingRequest,
    executor,
    object : CompanionDeviceManager.Callback() {
    // Called when a device is found. Launch the IntentSender so the user
    // can select the device they want to pair with.
    override fun onAssociationPending(intentSender: IntentSender) {
        intentSender?.let {
             startIntentSenderForResult(it, SELECT_DEVICE_REQUEST_CODE, null, 0, 0, 0)
        }
    }

    override fun onAssociationCreated(associationInfo: AssociationInfo) {
        // An association is created.
    }

    override fun onFailure(errorMessage: CharSequence?) {
        // To handle the failure.
     }
})

জাভা

CompanionDeviceManager deviceManager =
        (CompanionDeviceManager) getSystemService(Context.COMPANION_DEVICE_SERVICE);

Executor executor = new Executor() {
            @Override
            public void execute(Runnable runnable) {
                runnable.run();
            }
        };
deviceManager.associate(pairingRequest, new CompanionDeviceManager.Callback() {
    executor,
    // Called when a device is found. Launch the IntentSender so the user can
    // select the device they want to pair with.
    @Override
    public void onDeviceFound(IntentSender chooserLauncher) {
        try {
            startIntentSenderForResult(
                    chooserLauncher, SELECT_DEVICE_REQUEST_CODE, null, 0, 0, 0
            );
        } catch (IntentSender.SendIntentException e) {
            Log.e("MainActivity", "Failed to send intent");
        }
    }

    @Override
    public void onAssociationCreated(AssociationInfo associationInfo) {
        // An association is created.
    }

    @Override
    public void onFailure(CharSequence errorMessage) {
        // To handle the failure.
    });

Android 12L (API লেভেল 32) বা তার নিচের ভার্সনে (অবঞ্চিত):

কোটলিন

val deviceManager =
      requireContext().getSystemService(Context.COMPANION_DEVICE_SERVICE)

deviceManager.associate(pairingRequest,
    object : CompanionDeviceManager.Callback() {
        // Called when a device is found. Launch the IntentSender so the user
        // can select the device they want to pair with.
        override fun onDeviceFound(chooserLauncher: IntentSender) {
            startIntentSenderForResult(chooserLauncher,
                SELECT_DEVICE_REQUEST_CODE, null, 0, 0, 0)
        }

        override fun onFailure(error: CharSequence?) {
            // To handle the failure.
        }
    }, null)

জাভা

CompanionDeviceManager deviceManager =
        (CompanionDeviceManager) getSystemService(Context.COMPANION_DEVICE_SERVICE);
deviceManager.associate(pairingRequest, new CompanionDeviceManager.Callback() {
    // Called when a device is found. Launch the IntentSender so the user can
    // select the device they want to pair with.
    @Override
    public void onDeviceFound(IntentSender chooserLauncher) {
        try {
            startIntentSenderForResult(
                    chooserLauncher, SELECT_DEVICE_REQUEST_CODE, null, 0, 0, 0
            );
        } catch (IntentSender.SendIntentException e) {
            Log.e("MainActivity", "Failed to send intent");
        }
    }

    @Override
    public void onFailure(CharSequence error) {
        // To handle the failure.
    }
}, null);

ব্যবহারকারী নির্বাচনের ফলাফল আপনার কার্যকলাপের onActivityResult() অংশে ফেরত পাঠানো হয়। এরপর আপনি নির্বাচিত ডিভাইসটি অ্যাক্সেস করতে পারবেন।

যখন ব্যবহারকারী একটি ব্লুটুথ ডিভাইস নির্বাচন করেন, তখন একটি BluetoothDevice আশা করুন। যখন ব্যবহারকারী একটি ব্লুটুথ LE ডিভাইস নির্বাচন করেন, তখন একটি android.bluetooth.le.ScanResult আশা করুন। যখন ব্যবহারকারী একটি Wi-Fi ডিভাইস নির্বাচন করেন, তখন একটি android.net.wifi.ScanResult আশা করুন।

কোটলিন

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    when (requestCode) {
        SELECT_DEVICE_REQUEST_CODE -> when(resultCode) {
            Activity.RESULT_OK -> {
                // The user chose to pair the app with a Bluetooth device.
                val deviceToPair: BluetoothDevice? =
data?.getParcelableExtra(CompanionDeviceManager.EXTRA_DEVICE)
                deviceToPair?.let { device ->
                    device.createBond()
                    // Continue to interact with the paired device.
                }
            }
        }
        else -> super.onActivityResult(requestCode, resultCode, data)
    }
}

জাভা

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    if (resultCode != Activity.RESULT_OK) {
        return;
    }
    if (requestCode == SELECT_DEVICE_REQUEST_CODE && data != null) {
        BluetoothDevice deviceToPair =
data.getParcelableExtra(CompanionDeviceManager.EXTRA_DEVICE);
        if (deviceToPair != null) {
            deviceToPair.createBond();
            // Continue to interact with the paired device.
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

সম্পূর্ণ উদাহরণটি দেখুন:

Android 13 (API লেভেল 33) এবং উচ্চতর ভার্সন চালিত ডিভাইসগুলিতে:

কোটলিন

private const val SELECT_DEVICE_REQUEST_CODE = 0

class MainActivity : AppCompatActivity() {

    private val deviceManager: CompanionDeviceManager by lazy {
        getSystemService(Context.COMPANION_DEVICE_SERVICE) as CompanionDeviceManager
    }
    val mBluetoothAdapter: BluetoothAdapter by lazy {
        val java = BluetoothManager::class.java
        getSystemService(java)!!.adapter }
    val executor: Executor =  Executor { it.run() }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // To skip filters based on names and supported feature flags (UUIDs),
        // omit calls to setNamePattern() and addServiceUuid()
        // respectively, as shown in the following  Bluetooth example.
        val deviceFilter: BluetoothDeviceFilter = BluetoothDeviceFilter.Builder()
            .setNamePattern(Pattern.compile("My device"))
            .addServiceUuid(ParcelUuid(UUID(0x123abcL, -1L)), null)
            .build()

        // The argument provided in setSingleDevice() determines whether a single
        // device name or a list of them appears.
        val pairingRequest: AssociationRequest = AssociationRequest.Builder()
            .addDeviceFilter(deviceFilter)
            .setSingleDevice(true)
            .build()

        // When the app tries to pair with a Bluetooth device, show the
        // corresponding dialog box to the user.
        deviceManager.associate(pairingRequest,
            executor,
            object : CompanionDeviceManager.Callback() {
                // Called when a device is found. Launch the IntentSender so the user
                // can select the device they want to pair with.
                override fun onAssociationPending(intentSender: IntentSender) {
                intentSender?.let {
                    startIntentSenderForResult(it, SELECT_DEVICE_REQUEST_CODE, null, 0, 0, 0)
              }
            }

             override fun onAssociationCreated(associationInfo: AssociationInfo) {
                 // AssociationInfo object is created and get association id and the
                 // macAddress.
                 var associationId: int = associationInfo.id
                 var macAddress: MacAddress = associationInfo.deviceMacAddress
             }
             override fun onFailure(errorMessage: CharSequence?) {
                // Handle the failure.
            }
    )

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        when (requestCode) {
            SELECT_DEVICE_REQUEST_CODE -> when(resultCode) {
                Activity.RESULT_OK -> {
                    // The user chose to pair the app with a Bluetooth device.
                    val deviceToPair: BluetoothDevice? =
                        data?.getParcelableExtra(CompanionDeviceManager.EXTRA_DEVICE)
                    deviceToPair?.let { device ->
                        device.createBond()
                        // Maintain continuous interaction with a paired device.
                    }
                }
            }
            else -> super.onActivityResult(requestCode, resultCode, data)
        }
    }
}

জাভা

class MainActivityJava extends AppCompatActivity {

    private static final int SELECT_DEVICE_REQUEST_CODE = 0;
    Executor executor = new Executor() {
        @Override
        public void execute(Runnable runnable) {
            runnable.run();
        }
    };

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        CompanionDeviceManager deviceManager =
            (CompanionDeviceManager) getSystemService(
                Context.COMPANION_DEVICE_SERVICE
            );

        // To skip filtering based on name and supported feature flags,
        // do not include calls to setNamePattern() and addServiceUuid(),
        // respectively. This example uses Bluetooth.
        BluetoothDeviceFilter deviceFilter =
            new BluetoothDeviceFilter.Builder()
                .setNamePattern(Pattern.compile("My device"))
                .addServiceUuid(
                    new ParcelUuid(new UUID(0x123abcL, -1L)), null
                )
                .build();

        // The argument provided in setSingleDevice() determines whether a single
        // device name or a list of device names is presented to the user as
        // pairing options.
        AssociationRequest pairingRequest = new AssociationRequest.Builder()
            .addDeviceFilter(deviceFilter)
            .setSingleDevice(true)
            .build();

        // When the app tries to pair with the Bluetooth device, show the
        // appropriate pairing request dialog to the user.
        deviceManager.associate(pairingRequest, new CompanionDeviceManager.Callback() {
            executor,
           // Called when a device is found. Launch the IntentSender so the user can
           // select the device they want to pair with.
           @Override
           public void onDeviceFound(IntentSender chooserLauncher) {
               try {
                   startIntentSenderForResult(
                       chooserLauncher, SELECT_DEVICE_REQUEST_CODE, null, 0, 0, 0
                   );
               } catch (IntentSender.SendIntentException e) {
                   Log.e("MainActivity", "Failed to send intent");
               }
           }

          @Override
          public void onAssociationCreated(AssociationInfo associationInfo) {
                 // AssociationInfo object is created and get association id and the
                 // macAddress.
                 int associationId = associationInfo.getId();
                 MacAddress macAddress = associationInfo.getDeviceMacAddress();
          }

          @Override
          public void onFailure(CharSequence errorMessage) {
             // Handle the failure.
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        if (resultCode != Activity.RESULT_OK) {
            return;
        }
        if (requestCode == SELECT_DEVICE_REQUEST_CODE) {
            if (resultCode == Activity.RESULT_OK && data != null) {
                BluetoothDevice deviceToPair = data.getParcelableExtra(
                    CompanionDeviceManager.EXTRA_DEVICE
                );

                if (deviceToPair != null) {
                    deviceToPair.createBond();
                    // ... Continue interacting with the paired device.
                }
            }
        } else {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }
}

Android 12L (API লেভেল 32) বা তার নিচের ভার্সনে (অবঞ্চিত):

কোটলিন

private const val SELECT_DEVICE_REQUEST_CODE = 0

class MainActivity : AppCompatActivity() {

    private val deviceManager: CompanionDeviceManager by lazy {
        getSystemService(Context.COMPANION_DEVICE_SERVICE) as CompanionDeviceManager
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // To skip filters based on names and supported feature flags (UUIDs),
        // omit calls to setNamePattern() and addServiceUuid()
        // respectively, as shown in the following  Bluetooth example.
        val deviceFilter: BluetoothDeviceFilter = BluetoothDeviceFilter.Builder()
            .setNamePattern(Pattern.compile("My device"))
            .addServiceUuid(ParcelUuid(UUID(0x123abcL, -1L)), null)
            .build()

        // The argument provided in setSingleDevice() determines whether a single
        // device name or a list of them appears.
        val pairingRequest: AssociationRequest = AssociationRequest.Builder()
            .addDeviceFilter(deviceFilter)
            .setSingleDevice(true)
            .build()

        // When the app tries to pair with a Bluetooth device, show the
        // corresponding dialog box to the user.
        deviceManager.associate(pairingRequest,
            object : CompanionDeviceManager.Callback() {

                override fun onDeviceFound(chooserLauncher: IntentSender) {
                    startIntentSenderForResult(chooserLauncher,
                        SELECT_DEVICE_REQUEST_CODE, null, 0, 0, 0)
                }

                override fun onFailure(error: CharSequence?) {
                    // Handle the failure.
                }
            }, null)
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        when (requestCode) {
            SELECT_DEVICE_REQUEST_CODE -> when(resultCode) {
                Activity.RESULT_OK -> {
                    // The user chose to pair the app with a Bluetooth device.
                    val deviceToPair: BluetoothDevice? =
                        data?.getParcelableExtra(CompanionDeviceManager.EXTRA_DEVICE)
                    deviceToPair?.let { device ->
                        device.createBond()
                        // Maintain continuous interaction with a paired device.
                    }
                }
            }
            else -> super.onActivityResult(requestCode, resultCode, data)
        }
    }
}

জাভা

class MainActivityJava extends AppCompatActivity {

    private static final int SELECT_DEVICE_REQUEST_CODE = 0;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        CompanionDeviceManager deviceManager =
            (CompanionDeviceManager) getSystemService(
                Context.COMPANION_DEVICE_SERVICE
            );

        // To skip filtering based on name and supported feature flags,
        // don't include calls to setNamePattern() and addServiceUuid(),
        // respectively. This example uses Bluetooth.
        BluetoothDeviceFilter deviceFilter =
            new BluetoothDeviceFilter.Builder()
                .setNamePattern(Pattern.compile("My device"))
                .addServiceUuid(
                    new ParcelUuid(new UUID(0x123abcL, -1L)), null
                )
                .build();

        // The argument provided in setSingleDevice() determines whether a single
        // device name or a list of device names is presented to the user as
        // pairing options.
        AssociationRequest pairingRequest = new AssociationRequest.Builder()
            .addDeviceFilter(deviceFilter)
            .setSingleDevice(true)
            .build();

        // When the app tries to pair with the Bluetooth device, show the
        // appropriate pairing request dialog to the user.
        deviceManager.associate(pairingRequest,
            new CompanionDeviceManager.Callback() {
                @Override
                public void onDeviceFound(IntentSender chooserLauncher) {
                    try {
                        startIntentSenderForResult(chooserLauncher,
                            SELECT_DEVICE_REQUEST_CODE, null, 0, 0, 0);
                    } catch (IntentSender.SendIntentException e) {
                        // failed to send the intent
                    }
                }

                @Override
                public void onFailure(CharSequence error) {
                    // handle failure to find the companion device
                }
            }, null);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        if (requestCode == SELECT_DEVICE_REQUEST_CODE) {
            if (resultCode == Activity.RESULT_OK && data != null) {
                BluetoothDevice deviceToPair = data.getParcelableExtra(
                    CompanionDeviceManager.EXTRA_DEVICE
                );

                if (deviceToPair != null) {
                    deviceToPair.createBond();
                    // ... Continue interacting with the paired device.
                }
            }
        } else {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }
}

কম্প্যানিয়ন ডিভাইস প্রোফাইল

অ্যান্ড্রয়েড ১২ (এপিআই লেভেল ৩১) এবং তার উচ্চতর ভার্সনে, ঘড়ির মতো ডিভাইস পরিচালনা করে এমন কম্প্যানিয়ন অ্যাপগুলি কম্প্যানিয়ন ডিভাইস প্রোফাইল ব্যবহার করে সেটআপ প্রক্রিয়াটিকে সহজতর করতে পারে পেয়ার করার সময় প্রয়োজনীয় অনুমতি প্রদান করে। আরও তথ্যের জন্য, কম্প্যানিয়ন ডিভাইস প্রোফাইল দেখুন।

কম্প্যানিয়ন অ্যাপগুলিকে জাগিয়ে রাখুন

অ্যান্ড্রয়েড ১৬ (এপিআই লেভেল ৩৬) দিয়ে শুরু করে,

CompanionDeviceManager.startObservingDevicePresence(String) এবং CompanionDeviceService.onDeviceAppeared() বন্ধ করা হয়েছে।

  • আপনার বাস্তবায়িত CompanionDeviceService এর বাইন্ডিং স্বয়ংক্রিয়ভাবে পরিচালনা করতে আপনার CompanionDeviceManager.startObservingDevicePresence (ObservingDevicePresenceRequest) ব্যবহার করা উচিত।

    • আপনার CompanionDeviceService এর বাইন্ডিং অবস্থা স্বয়ংক্রিয়ভাবে এর সংশ্লিষ্ট Companion ডিভাইসের উপস্থিতির অবস্থার উপর ভিত্তি করে পরিচালিত হয়:
      1. যখন কম্প্যানিয়ন ডিভাইসটি BLE রেঞ্জের মধ্যে থাকে অথবা ব্লুটুথ ব্যবহার করে সংযুক্ত থাকে তখন পরিষেবাটি আবদ্ধ থাকে।
      2. যখন কম্প্যানিয়ন ডিভাইসটি BLE রেঞ্জের বাইরে চলে যায় অথবা এর ব্লুটুথ সংযোগ বন্ধ হয়ে যায় তখন পরিষেবাটি আনবাউন্ড হয়ে যায়।
  • অ্যাপটি DevicePresenceEvent এর বিভিন্ন ধরণের উপর ভিত্তি করে কলব্যাক পাবে।

    বিস্তারিত জানার জন্য, CompanionDeviceService.onDeviceEvent() দেখুন।