How to enable bluetooth phone programmatically without user permission?

I am developing an Android application that allows the user to control the central locking system of their car, thereby eliminating the need for a small remote key tag. But according to what I have done so far, every time a user opens the application, his phone must be turned on manually, as it asks for user permission.

So I need to know if there is a way to enable the bluetooth-bluetooth adapter programmatically, so that every time the application starts, the bluetooth of the phone will be turned on automatically.

Hope my question is clear. I am new to Android programming.

Ps - If you are interested in how the connection is made between the phone and the car, there are some schemes and a bluetooth module connected to the microcontroller in the car.

+4
source share
2 answers

Yes it is possible.

btAdapter = BluetoothAdapter.getDefaultAdapter(); if (btAdapter == null) { // Device does not support Bluetooth Toast.makeText(getApplicationContext(), "Device does not support bluetooth", Toast.LENGTH_LONG).show(); } else { if (!btAdapter.isEnabled()) { btAdapter.enable(); Toast.makeText(getApplicationContext(), "Bluetooth switched ON", Toast.LENGTH_LONG).show(); } 
+3
source

In addition to the SoulRayder code

You will need to add usage permission in the AndroidManifest.xml file in the application > manifestests.

 <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> 

This happens before the <application> , but inside the <manifest>

0
source

Source: https://habr.com/ru/post/1491688/


All Articles