I'm trying to make an implementation to display paired Bluetooth devices and those connected around a mobile phone. I made several searches , I found a example and now I'm trying to build a my implementation. What I want is to build a class called Bluetooth which has the following implementations:
A method to check if your phone's Bluetooth is enabled, if not, enable it. A list of paired and connected devices. A method for connecting to the Bluetooth device.
So I started the development, arriving at the following code:
package br.ufscar.dc.controledepatrimonio.Util.RFID;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
import br.ufscar.dc.controledepatrimonio.R;
public class Bluetooth extends BroadcastReceiver {
private BluetoothAdapter dispositivo;
private Activity activity;
public Bluetooth (Activity activity) {
dispositivo = BluetoothAdapter.getDefaultAdapter();
this.activity = activity;
}
private void habilitarConexao(Bluetooth bluetooth) {
if (bluetooth.dispositivo == null) {
Toast.makeText(activity, R.string.msg_bluetooth_nao_suportado, Toast.LENGTH_LONG);
}
if (!bluetooth.dispositivo.isEnabled()) {
Intent i = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
activity.startActivity(i, REQUEST_ENABLE_BT);
}
}
@Override
public void onReceive(Context context, Intent intent) {
}
}
The problem is that the REQUEST_ENABLE_BT constant has the following error: "Can not resolve symbol 'REQUEST_ENABLE_BT'" I even found a post on that, and I did what is commented there, but another error occurs: "Wrong 2nd argument type. Found: 'int'. Required: 'android.os.Bundle'"
I wonder why. Since if I do the same encoding in an Activity it works normally. Thanks in advance for the help !!