1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-23 16:53:04 +02:00

add some try catch blocks

This commit is contained in:
OliE
2017-09-29 19:40:59 +02:00
parent dc820d8118
commit 1b6bddbbcc
3 changed files with 36 additions and 26 deletions

View File

@@ -22,6 +22,7 @@ import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.widget.Toast;
import com.health.openscale.core.alarm.AlarmHandler;
import com.health.openscale.core.bluetooth.BluetoothCommunication;
@@ -114,16 +115,22 @@ public class OpenScale {
public ScaleUser getSelectedScaleUser()
{
ScaleUser scaleUser = new ScaleUser();
try {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
int selectedUserId = prefs.getInt("selectedUserId", -1);
if (selectedUserId == -1) {
ScaleUser scaleUser = new ScaleUser();
return scaleUser;
}
return scaleUserDB.getScaleUser(selectedUserId);
scaleUser = scaleUserDB.getScaleUser(selectedUserId);
} catch (Exception e) {
Toast.makeText(context, "Error: " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
return scaleUser;
}
public void deleteScaleUser(int id)

View File

@@ -430,13 +430,13 @@ public abstract class BluetoothCommunication {
{
@Override
public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
try {
if (device.getName() == null) {
return;
}
for (int i = 0; i < hwAddresses().size(); i++) {
if (device.getAddress().replace(":", "").toUpperCase().startsWith(hwAddresses().get(i)) || hwAddresses().get(i) == "FFFFFF")
{
if (device.getAddress().replace(":", "").toUpperCase().startsWith(hwAddresses().get(i)) || hwAddresses().get(i) == "FFFFFF") {
if (isDeviceNameCheck()) {
if (!device.getName().toLowerCase().equals(btDeviceName.toLowerCase())) {
return;
@@ -451,6 +451,9 @@ public abstract class BluetoothCommunication {
btAdapter.stopLeScan(scanCallback);
}
}
} catch (Exception e) {
setBtStatus(BT_STATUS_CODE.BT_UNEXPECTED_ERROR, e.getMessage());
}
}
};
}

View File

@@ -89,7 +89,7 @@ public class BluetoothCustomOpenScale extends BluetoothCommunication {
for (BluetoothDevice device : pairedDevices) {
// check if we can found bluetooth device name in the pairing list
if (device.getName().equals(deviceName)) {
if (device != null && device.getName().equals(deviceName)) {
btDevice = device;
try {