Achal Sharma
Achal Sharma

Reputation: 152

Cannot resolve symbol 'REQUEST_ENABLE_BLUETOOTH'

I am trying to implement a feature which checks if Bluetooth is enabled or not. I keep getting: Cannot resolve symbol 'REQUEST_ENABLE_BLUETOOTH'. I am a beginner in Java and just started working in Android Studio for an Internship project.

package achal.xylotron.com.bluespot;

import android.app.Activity;
import android.os.Bundle;
import android.bluetooth.*;
import android.content.Intent;

public class BlueChat extends Activity
{

    BluetoothAdapter bluetoothAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.blue_chat);

        bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

        if (!bluetoothAdapter.isEnabled())
        {
            Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(enableIntent, REQUEST_ENABLE_BLUETOOTH);
        }
    }
}

Upvotes: 3

Views: 2328

Answers (1)

Omkar
Omkar

Reputation: 3100

initialize REQUEST_ENABLE_BLUETOOTH int like below

package achal.xylotron.com.bluespot;

import android.app.Activity;
import android.os.Bundle;
import android.bluetooth.*;
import android.content.Intent;

public class BlueChat extends Activity
{

    BluetoothAdapter bluetoothAdapter;
    int REQUEST_ENABLE_BLUETOOTH = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.blue_chat);

        bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

        if (!bluetoothAdapter.isEnabled())
        {
            Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(enableIntent, REQUEST_ENABLE_BLUETOOTH);
        }
    }
}

Upvotes: 2

Related Questions