Q.
Develope a program to TRUN ON and OFF the bluetooth, Write the Java file and
permission tags.
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
private BluetoothAdapter bluetoothAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
// Initialize BluetoothAdapter
bluetoothAdapter = [Link]();
// Check if device supports Bluetooth
if (bluetoothAdapter == null) {
[Link](this, "Device does not support Bluetooth", Toast.LENGTH_SHORT).show();
finish();
// Method to turn on Bluetooth
private void enableBluetooth() {
if (![Link]()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivity(enableBtIntent);
} }
// Method to turn off Bluetooth
private void disableBluetooth() {
if ([Link]()) {
[Link]();
} } }
[Link] (Permissions)
<manifest xmlns:android="[Link]
package="[Link]">
<uses-permission android:name="[Link]" />
<uses-permission android:name="[Link].BLUETOOTH_ADMIN" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity>
</application>
</manifest>