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

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

Related

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.

Show only bluetooth system settings activity and nothing else

My question is similar to Android Wifi Settings within app(Kiosk-sh app) but for Bluetooth settings.
In short I have an app running in Kiosk Mode and want to show Bluetooth settings.
If I use
Intent intentBluetooth = new Intent();
intentBluetooth.setAction(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS);
startActivity(intentBluetooth);
Bluetooth settings are shown along with all other system settings (application manager, Wi-Fi etc.). I want to limit user to only Bluetooth settings and nothing else (like Wi-Fi in above answer).
com.android.settings.bluetooth package has 3 different activities but none of them suit my needs. Is there a way to get similar system activity for Bluetooth as there is for Wi-Fi?
Code you are using is working just fine. It may depends on concrete implementation on device OS.

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.

(Android && Bluetooth) Make device discoverable from service without user interaction?

I would like to beable to automatically turn on discoverability on an android device without the user being prompted with a security dialog.
I'm developing two applications, one for an Android TV box, one for my smartphone. I want to be able to control the android TV box using my smartphone, however I want to do this without needing to turn on discoverability manually on the TV box as that would require a remote of some kind completely defeating the point of the application.
Is there another way to enable discoverability through API which I could use - preferably via a service.
thanks,
Nathan.
Wow, 4 years go.
As an answer to my younger self I would think that what you were trying to do is not possible as you said so yourself, it's a matter of security (You yourself reference a "sercuity dialog").
If an app could turn on Bluetooth whenever it wished and had full covert access to the entire Bluetooth hardware, then the app could potentially with malicious intent damage parts of the Android OS and delete or worse; distribute the User's personal information.
What you would be looking at instead is implementing the system that computer peripheral manufactures implement with wireless keyboard and mice, that is to extract the Bluetooth connectivity to a separate hardware layer (A usb dongle) and via USB implement a human interface device, thus in turn filtering the Bluetooth connection to allow only the sending of HID input information to the device.
To myself 4 years ago,
Nathan.
A bit late, but you need to do this with an intent, from the documentation on Android Bluetooth:
Intent discoverableIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivity(discoverableIntent);
http://developer.android.com/guide/topics/connectivity/bluetooth.html#EnablingDiscoverability

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