Reputation: 802
I have an app that connects to a device using SPP, and for some reason, our Acer Iconia One B3-A10 won't connect to this device. Our other tablets have no issue connecting.
Here is my code:
public class BluetoothConnectionService {
Context mContext;
static BluetoothAdapter btAdapter;
static ArrayList<BluetoothDevice> pairedDevices;
static BluetoothDevice selectedDevice;
static BluetoothSocket socket;
static InputStream inStream;
static OutputStream outStream;
public static boolean isBluetoothEnabled() {
btAdapter = BluetoothAdapter.getDefaultAdapter();
if (btAdapter == null) {
return false;
} else {
if (!btAdapter.isEnabled()) {
// Bluetooth is not enabled :)
return false;
} else {
return true;
}
}
}
public static ArrayList<BluetoothDevice> getPairedDevices() {
btAdapter = BluetoothAdapter.getDefaultAdapter();
Set<BluetoothDevice> devices = btAdapter.getBondedDevices();
if (devices.size() > 0) {
pairedDevices = new ArrayList<BluetoothDevice>();
for (BluetoothDevice device : devices) {
pairedDevices.add(device);
}
}
return pairedDevices;
}
static void sendMessage(BluetoothSocket socket, String msg) {
OutputStream outStream;
if (socket != null) {
try {
outStream = socket.getOutputStream();
outStream.write(msg.getBytes());
} catch (IOException e) {
Log.d("BLUETOOTH_COMMS", e.getMessage());
}
}
}
public static void setDevice(BluetoothDevice device) {
selectedDevice = device;
}
public static BluetoothDevice getDevice() {
return selectedDevice;
}
public static void setSocket(BluetoothSocket msocket) {
socket = msocket;
}
public static void closeSocket() {
try {
if (socket != null) {
socket.close();
}
} catch (IOException e) {
Log.e("Error", "Could not close socket!");
}
}
public static BluetoothSocket getSocket() {
return socket;
}
public static void setInStream(InputStream inStream) {
inStream = inStream;
}
public static void setOutStream(OutputStream outStream) {
outStream = outStream;
}
public static InputStream getInStream() {
return inStream;
}
public static OutputStream getOutStream() {
return outStream;
}
}
public abstract class ConnectTask extends AsyncTask<Void, Void, Void> {
Context mContext;
BluetoothDevice mdevice;
BluetoothSocket mSocket;
ProgressDialog pd;
public ConnectTask(Context context) {
mContext = context;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
if (pd !=null) {
pd = null;
}
pd = new ProgressDialog(mContext);
pd.setTitle("Connecting...");
pd.setCancelable(false);
if (!pd.isShowing()) {
pd.show();
}
}
@Override
protected Void doInBackground(Void... params) {
try {
mdevice = BluetoothConnectionService.getDevice();
UUID uuid = mdevice.getUuids()[0].getUuid();
mSocket = mdevice.createRfcommSocketToServiceRecord(uuid);
mSocket=mdevice.createInsecureRfcommSocketToServiceRecord(uuid);
mSocket.connect();
} catch (IOException e) {
Log.e("Error", "Could not connect socket!");
if (mSocket != null) {
try {
mSocket.close();
} catch (IOException e1) {
Log.e("Error", "Can't close socket!");
}
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
try {
if (pd != null) {
if (pd.isShowing()) {
pd.dismiss();
}
}
} catch (final IllegalArgumentException are) {
Log.e("Error", "Illegal Argument Exception);
} finally {
pd = null;
}
BluetoothConnectionService.setSocket(mSocket);
onComplete();
}
//start session
abstract void onComplete();
public void dismissDialog() {
if (pd != null) {
if (pd.isShowing()) {
pd.dismiss();
}
}
pd = null;
}
}
Is there any way to get the Acer Iconia One B3-A10 to connect? Or is there a hardware limitation that prevents it?
Upvotes: 1
Views: 30