So while looking for a fix for the bluetooth connection crashing I've found a filed bug report for Android 5 bluetooth issues. They aren't specific to BLE and they seem to all be coming from owners of Nexus and recent Motorola devices. All of which run a vanilla version of Android 5. Having found this and thinking that it was simply an issue with Android 5, I tried the Nordic Semiconductor's app "nRF UART v2.0" and low and behold, it works. Kind of. The watch disconnects like crazy, but I can get it to receive messages I send. The letter D followed by the time in a "yyyy MM dd h m s" format will set the time and get the counter started on the Arduino, sending a 1 followed by a message shows on the top line of the bottom of the screen and sending a 2 shows on the bottom line.
These tests prove that the phone and the OS aren't the reason the app isn't working. This is a plus. I'm just not sure what part of the app isn't working. :/
Edit: It looks like Android 5.0 had a major update to the BluetoothLE scanning API to reduce power consumption. That info is documented here:
http://developer.radiusnetworks.com/2014/10/28/android-5.0-scanning.htmlFar as I can tell, the older offending code lies in this block. Lines 108-146 of ScanActivity.java. Android studio is enjoying pointing out that 'startLeScan' and 'stopLeScan' are currently depreciated. I'll attempt to adjust this code tomorrow. Currently, I'm a bit too sleepy. Also, Ben Rose might be a bit better at doing this if he has time.
private BluetoothAdapter.LeScanCallback mLeScanCallback =
new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(final BluetoothDevice device, int rssi,
byte[] scanRecord) {
runOnUiThread(new Runnable() {
@Override
public void run() {
mLeDeviceListAdapter.addDevice(device);
mLeDeviceListAdapter.notifyDataSetChanged();
}
});
}
};
private void scanLeDevice(final boolean enable) {
if (enable) {
handler = new Handler();
// Stops scanning after a pre-defined scan period.
handler.postDelayed(new Runnable() {
@Override
public void run() {
//Debug.ShowText(getApplicationContext(),"scan timed out after " + SCAN_PERIOD/1000 + " seconds.");
isScanning = false;
mBluetoothAdapter.stopLeScan(mLeScanCallback);
invalidateOptionsMenu();
}
}, SCAN_PERIOD);
isScanning = true;
mBluetoothAdapter.startLeScan(mLeScanCallback);
} else {
isScanning = false;
mBluetoothAdapter.stopLeScan(mLeScanCallback);
}
}