Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): add requestEnable method #591

Merged
merged 1 commit into from
Nov 2, 2023
Merged

feat(android): add requestEnable method #591

merged 1 commit into from
Nov 2, 2023

Conversation

pwespi
Copy link
Member

@pwespi pwespi commented Nov 2, 2023

closes #590

@pwespi pwespi merged commit 79c5742 into main Nov 2, 2023
4 checks passed
@pwespi pwespi deleted the enable-android-33 branch November 2, 2023 20:01
@gregoiregentil
Copy link

Thank you for taking of #590. But don't you think that RequestEnable API should be integrated into Enable API? Because it takes care of the same feature but with different Android version. Am I clear in my comment? Or do you think that the user should check the Android version in his typescript logic?

@peitschie
Copy link
Collaborator

Just in case it's of any interest, here's an example of how this intent-based approach can be wired up so the success/fail result can still be returned via the promise-based API: https://github.com/don/cordova-plugin-ble-central/blob/073c80dbc269341a4822663bde85d090e98d32c4/src/android/BLECentralPlugin.java#L1332-L1350 (obviously, some adaption required!)

(Just driving by while checking if I needed this change too!)

@gregoiregentil
Copy link

My understanding (my wish) is to keep only the Enable call in my app. And in the Android code of the plugin, it should detect that we are in version 33+ of Android, so then it should use onActivityResult as explained in the previous comment, which will trigger the OS to show the new popup for the user to enable Bluetooth. Am I misunderstanding?

@pwespi
Copy link
Member Author

pwespi commented Nov 4, 2023

Thank you all for your feedback.

I understand that you would like to have a single method to call in your app. My goal was that requestEnable would become that method. It should handle the result properly, as mentioned by @peitschie (thank you for the link!). This will be fixed with: #595.

In general I'd like to avoid that a method has a different implementation depending on the SDK version (which is not always possible). And the implementation with ACTION_REQUEST_ENABLE actually works on all supported Android versions. Therefore my plan was to have the new method requestEnable which supports all version and deprecate enable. I should probably have used the implementation with ACTION_REQUEST_ENABLE from the beginning, like the cordova-plugin-ble-central plugin does, and never have used the bluetoothAdapter.enable(). The Android documentation says:

The enable() method is provided only for applications that include a user interface for changing system settings, such as a "power manager" app.

So it was meant for "power manager" apps, and not for apps that just use Bluetooth. That's another reason why I would like to deprecate it.

@gregoiregentil Once #595 is merged, would you be able to switch to requestEnable completely, or is there a problem with that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable() not working on API33+ (Android 13+)
3 participants