Android : unable to enable bluetooth adapter - android

I am running an embedded system on android 2.1. The system has a bluetooth chip.
Calling getDefaultAdapter returns an adapter so BT is available
however i'm not able to enable the adapter even when user gives permission.
I also tried using bluetoothadapter.enable() and its still not working.
I've tested the code on a phone and it works,
What could be going wrong?

Do not use without explicit user action to turn on Bluetooth.
Bluetooth should never be enabled without direct user consent.
See the documentation.

Related

Read vendor-specific BLE HID reports on Android

I have a project in which I have to read vendor-specific data from a custom BLE device in Android. However, everywhere I looked says that Android "absorbs" HID reports and has no access points for it either through JDK or NDK.
I even tried to create a "priv-app" application and get the BLUETOOTH_PRIVILEGED permission to enable notifications on every characteristic of service 1812, but with no luck (notifications are enabled, but I'm never notified of an event).
Is there any possible way of doing this without building a custom version of Android?
Thanks in advance

Android BLE difference between BlutoothAdapter.enable(); and call an intent

While working with the Blutooth low energy I need to mantain the Bluetooth adapter on.
Recently I've realized that it can be turned on in two different ways.
First way:
BluetoothAdapter.getDefaultAdapter().enable();
First time I tryed this function I thought this required root or some kind of privileges to work.
Actually I find out none of them is necessary and this function works fine on different devices.
(Samsung S4 Lollipop, Asus Zenpad 8" Marshmellow, Meizu M2 Note Lollipop)
Second way:
enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, ENABLE_BLUETOOTH_INTENT);
By using the intent you can ask the user to turn on the Bluetooth. This one works fine too but you have to listen for intent result. So this require more code and the user can decide to not turn on the bluetooth.
Do they works fine in every situation? Is there a "better" one? What is the real difference between them?
As per documentation:
Bluetooth should never be enabled without direct user consent. If you want to turn on Bluetooth in order to create a wireless connection, you should use the ACTION_REQUEST_ENABLE Intent, which will raise a dialog that requests user permission to turn on Bluetooth. The enable() method is provided only for applications that include a user interface for changing system settings, such as a "power manager" app.
So basically the reason to use Intent is just a good UX. I advise to use Intent because of that reason.
In order to use BLE in your Application for receiving and transmitting data among device we must require blutooth enabled.
Another point is that device suport BLE or not.
Bluetooth adapter required for doing bluetooth related stuff.
If blutooth is not enabled on device , then ask for user to enable it by using intent and listen for intent. So this more code required.
If user do not turn on bluetooth we can't do BLE related things.
So, require bluetooth adapter and bluetooth on device and enable method provides user interface for changing system settings.

Android Awareness of remote Bluetoth-Request with disabled BluetoothAdapter

I'd like to use android's bluetooth for some kind of sensing devices. But I don't want to connect to these devices. As far as I know Devices won't react to scanning when their own bluetooth is disabled. But is there any way to get my app noticed when such a scan has been performed by a remote device, even when my app is running with bluetooth turned off?
I don't want to force toggling bluetooth on, but I need to get some kind of Action started in other devices running the same app. So I'm wondering if some there is any description/data field that can be sent with a bluetooth scan, so if scan is rejected the app has the opportunity to read that data just to know there was this specific call?
I need to leverage context-awareness within my system as to users, not knowing each other, still can interchange content (if they agree). But I need to find some ways of sensing while I also don't want to have all sensors activated all the time.
Hope you can give me a hint, or tell me that this is simply not possible, which would also help me not spending any more time on that.
Thanks.

App Inventor 2 - Disable the Device Bluetooth when app closes?

I can set a variavle when the app initialises to thell me if the Device Bluetooth is enabled.
There doesn't seem to be a method to enable Bluetooth from within the app, so I'm showing a notifier "Enable Bluetooth in Device Settings", but I'd really like to be able to disable Bluetooth when the app closes (if it was originally disabled - hence the variable) to conserve battery life.
Can this be done?
Thanks
This does not appear possible using AppInventor at this time.
It does appear that you have the ability to directly turn on Bluetooth, however, using the Android Bluetooth intent and the AI2 Activity Starter component. See (http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html) for reference and (http://www.whatakuai.com/bluetooth-and-app-inventor/) for implementation.
Sadly there does not appear to be a public Intent you can use to disable the bluetooth radio using the ActivityStarter component.
use the application Bluetooth Auto Off
it dissable the bluetooth after there is no comunication for selected time
https://play.google.com/store/apps/details?id=com.mst.btautodisable

Is it possible to lock the bluetooth in android device for a specific time period

I am able to disable Bluetooth using Bluetooth API`s Disable method .but my requirement is also to prevent the user interaction for Bluetooth when my apps is running.Is there any way to prevent the user interaction i.e when the user try to enable Bluetooth the app will block it.
Thanks in advance.
This is a small piece of code that needs to be written to disable/block bluetooth access. However, if you want to modify the functionality lagely, rooting is the solution. However, this post is already having relevance to the one noted ast : How to enable/disable bluetooth programmatically in android

Categories

Resources