diff --git a/android-uribeacon/uribeacon-library/src/main/java/org/uribeacon/beacon/ConfigUriBeacon.java b/android-uribeacon/uribeacon-library/src/main/java/org/uribeacon/beacon/ConfigUriBeacon.java
index 7db90f9..6278d1c 100644
--- a/android-uribeacon/uribeacon-library/src/main/java/org/uribeacon/beacon/ConfigUriBeacon.java
+++ b/android-uribeacon/uribeacon-library/src/main/java/org/uribeacon/beacon/ConfigUriBeacon.java
@@ -20,6 +20,8 @@
public class ConfigUriBeacon extends UriBeacon {
private static final String TAG = ConfigUriBeacon.class.getCanonicalName();
+ // This error should be defined in the BluetoothGatt library but it isn't.
+ public static final int INSUFFICIENT_AUTHORIZATION = 8;
public static final int PERIOD_NONE = -1;
public static final byte POWER_MODE_NONE = -1;
public static final byte POWER_MODE_ULTRA_LOW = 0;
diff --git a/android-uribeacon/uribeacon-sample/src/main/java/org/uribeacon/sample/ConfigActivity.java b/android-uribeacon/uribeacon-sample/src/main/java/org/uribeacon/sample/ConfigActivity.java
index 749d8bf..2b2732d 100644
--- a/android-uribeacon/uribeacon-sample/src/main/java/org/uribeacon/sample/ConfigActivity.java
+++ b/android-uribeacon/uribeacon-sample/src/main/java/org/uribeacon/sample/ConfigActivity.java
@@ -71,38 +71,44 @@ public class ConfigActivity extends Activity implements PasswordDialogFragment.P
private final UriBeaconCallback mUriBeaconCallback = new UriBeaconCallback() {
@Override
public void onUriBeaconRead(ConfigUriBeacon configUriBeacon, int status) {
- checkRequest(status);
- updateInputFields(configUriBeacon);
+ if (status == BluetoothGatt.GATT_SUCCESS) {
+ updateInputFields(configUriBeacon);
+ } else if (status == BluetoothGatt.GATT_FAILURE) {
+ Toast.makeText(ConfigActivity.this, R.string.failed_to_read, Toast.LENGTH_SHORT).show();
+ finish();
+ } else {
+ Toast.makeText(ConfigActivity.this, getString(R.string.failed_with_code) + status, Toast.LENGTH_SHORT).show();
+ finish();
+ }
}
@Override
public void onUriBeaconWrite(int status) {
- checkRequest(status);
- mUriBeaconConfig.closeUriBeacon();
- finish();
- }
-
- private void checkRequest(int status) {
- if (status == BluetoothGatt.GATT_FAILURE) {
- Toast.makeText(ConfigActivity.this, "Failed to update the beacon", Toast.LENGTH_SHORT)
- .show();
+ if (status == BluetoothGatt.GATT_SUCCESS) {
+ mUriBeaconConfig.closeUriBeacon();
finish();
+ } else if (status == BluetoothGatt.GATT_FAILURE) {
+ Toast.makeText(ConfigActivity.this, R.string.failed_to_write, Toast.LENGTH_SHORT).show();
+ } else if (status == ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION) {
+ Toast.makeText(ConfigActivity.this, R.string.wrong_password, Toast.LENGTH_SHORT).show();
+ } else {
+ Toast.makeText(ConfigActivity.this, getString(R.string.failed_with_code) + status, Toast.LENGTH_SHORT).show();
}
+ enableUi(true);
}
};
- private void blockUi() {
- mSchema.setEnabled(false);
- mUriValue.setEnabled(false);
- mFlagsValue.setEnabled(false);
+ private void enableUi(boolean block) {
+ mSchema.setEnabled(block);
+ mUriValue.setEnabled(block);
+ mFlagsValue.setEnabled(block);
for (EditText txCal : mAdvertisedTxPowerLevels) {
- txCal.setEnabled(false);
+ txCal.setEnabled(block);
}
- mTxPowerMode.setEnabled(false);
- mBeaconPeriod.setEnabled(false);
- mLockState.setEnabled(false);
+ mTxPowerMode.setEnabled(block);
+ mBeaconPeriod.setEnabled(block);
+ mLockState.setEnabled(block);
}
-
public void saveConfigBeacon(MenuItem menu) {
try {
if (mUriBeaconConfig.getVersion().equals(ProtocolV2.CONFIG_SERVICE_UUID)) {
@@ -114,7 +120,7 @@ public void saveConfigBeacon(MenuItem menu) {
}
}
else {
- blockUi();
+ enableUi(false);
ConfigUriBeacon configUriBeacon = new ConfigUriBeacon.Builder()
.uriString(getUri())
.txPowerLevel(DEFAULT_TX_POWER)
@@ -136,6 +142,7 @@ public void onResetClicked(MenuItem menu) {
}
private void resetConfigBeacon(byte[] key) {
try {
+ enableUi(false);
ConfigUriBeacon configUriBeacon = new ConfigUriBeacon.Builder()
.key(key)
.reset(true)
@@ -146,7 +153,7 @@ private void resetConfigBeacon(byte[] key) {
}
}
private void writeUriBeaconV2(byte[] key) throws URISyntaxException {
- blockUi();
+ enableUi(false);
ConfigUriBeacon.Builder builder = new ConfigUriBeacon.Builder()
.key(key)
.lockState(mLockState.isChecked())
diff --git a/android-uribeacon/uribeacon-sample/src/main/res/values/strings.xml b/android-uribeacon/uribeacon-sample/src/main/res/values/strings.xml
index b961dfe..51431bb 100644
--- a/android-uribeacon/uribeacon-sample/src/main/res/values/strings.xml
+++ b/android-uribeacon/uribeacon-sample/src/main/res/values/strings.xml
@@ -62,4 +62,8 @@
Could not reset UriBeacon to its default values
Please enter a password
Passwords don\'t match
+ Failed to read beacon
+ Failed with code:
+ Wrong password please try again...
+ Failed to update beacon