0% found this document useful (0 votes)
8 views2 pages

Q. Develope A Program To TRUN ON and OFF The Bluetooth, Write The Java File and Permission Tags

The document provides a Java program for an Android application that can turn Bluetooth on and off using the BluetoothAdapter class. It includes methods to enable and disable Bluetooth, along with necessary permission tags in the AndroidManifest.xml file. The application checks if the device supports Bluetooth and displays a message if it does not.

Uploaded by

adityazz603
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Q. Develope A Program To TRUN ON and OFF The Bluetooth, Write The Java File and Permission Tags

The document provides a Java program for an Android application that can turn Bluetooth on and off using the BluetoothAdapter class. It includes methods to enable and disable Bluetooth, along with necessary permission tags in the AndroidManifest.xml file. The application checks if the device supports Bluetooth and displays a message if it does not.

Uploaded by

adityazz603
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Q.

Develope a program to TRUN ON and OFF the bluetooth, Write the Java file and
permission tags.
import android.bluetooth.BluetoothAdapter;

import android.content.Context;

import android.content.Intent;

import android.os.Bundle;

import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private BluetoothAdapter bluetoothAdapter;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// Initialize BluetoothAdapter

bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

// Check if device supports Bluetooth

if (bluetoothAdapter == null) {

Toast.makeText(this, "Device does not support Bluetooth", Toast.LENGTH_SHORT).show();

finish();

// Method to turn on Bluetooth

private void enableBluetooth() {

if (!bluetoothAdapter.isEnabled()) {

Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);

startActivity(enableBtIntent);
} }

// Method to turn off Bluetooth

private void disableBluetooth() {

if (bluetoothAdapter.isEnabled()) {

bluetoothAdapter.disable();

} } }

AndroidManifest.xml (Permissions)
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bluetooth">
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.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="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy