1
I’m trying to perform an implementation to display paired Bluetooth devices and those connected around a mobile phone. I did several research, I found a example and now I’m trying to build an implementation of mine. What I want is to build a class called Bluetooth which has the following implementations:
A method to check if the mobile’s Bluetooth is enabled, if not, enable. A list of paired and connected devices. A method to connect with 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 presents the following error: "Cannot resolve Symbol 'REQUEST_ENABLE_BT'" I even found a post about it, and I did what is commented there, but another error occurs: "Wrong 2nd argument type. Found: 'int'. required: 'android.os.Bundle'"
I would like to know why. Since if I do the same coding in an Activity it works normally. Thanks in advance for the help!!