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.
Related
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.
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
I am little confused about System.Global. According to this document (third point under Important Behavioral Changes) it says that few of the features like turning airplane mode on/off have been include in System.Global in Android 4.2 and higher so its now read only we cannot write it.
Along with airplane mode there is also Bluetooth turn on/off feature included in System.Global which means we shouldn't be able to toggle Bluetooth on/off programmatically since its read only.
But I have some app in my Nexus 7 which runs on version 4.4.2 where the app can easily turn on/off Bluetooth on voice command (one such app is 'Assistant')
How is it possible if the features in System.Global are read only?
Any explanation on this topic will be very much appreciated. Thanks in advance :)
System settings are generally read-only for normal apps. The "Assistant" or "Settings" applications are bundled with the platform and have special permissions. Bluetooth does expose the ability to turn a given "adapter" off and on via the BluetoothAdapter class.
Starting with Android 5.0, it's possible to access some of the settings.
You can use the method setGlobalSetting() in the DevicePolicyManager for that.
However, the caller app must be device owner which is not available to apps deployed on Google Play.
To deploy and activate a device owner, you must perform an NFC data
transfer from a programming app to the device while the device is in
its unprovisioned state. This data transfer sends the same information
as in the provisioning intent described in Managed provisioning.
Source: Android 5.0 APIs
I have an app running on Android that uses only a webview to display a mobile web-application and at some point uses the device's GPS to obtain their position.
I have a custom ChromeWebClient etc and it obtains their position nicely except for on devices where the Power Saving Mode is enabled?
Is there anyway in the SDK/API for me to be able to determine if the user has this enabled and to advise them accordingly?
I can't find anything in the docs so i am assuming not but worth a shot,
Cheers,
Lee
After reeding the comments
In my experience Samsung, as well as HTC, is one of the manufacturers that modify Android OS in most unpredictable ways. They add new functions and modes, like 4G switching launcher widgets and "power saving mode". They modify permission requirements for documented SDK methods, i.e. to switch on bluetooth on a Samsung device your app needs to have and additional android.permission.BLUETOOTH permission, while stock Android only needs android.permission.BLUETOOTH_ADMIN. And there's more.
Long story short, as #RaghavSood pointed out, "power saving mode" is not an official AOSP feature and there are no ways to detect it via official SDK. There is a possible way how you can work around it though. I believe it is most likely that your app misbehaves in power saving mode because this mode turns off GPS. You can confirm that by configuring power saving mode in settings to disable GPS disabling(can't phrase this better, sorry) - first link from google with steps. Then test the app. Does it work? If yes, then you've rootcaused the problem and now your job is to let the user know that your app won't run without GPS. You can put some code into your app to detect if GPS service is enabled an show an alert dialog if it isn't. The code in your activity can look something like this:
LocationManager lm = getSystemService(Context.LOCATION_SERVICE);
if(!lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
//Show a notification prompting user to switch on GPS.
}
You can be even more elaborate and make your app detect device manufacturer to show a custom message on all Samsung devices.
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