diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSDeviceSupport.java
index 5782c1306..c2929f25b 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSDeviceSupport.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSDeviceSupport.java
@@ -105,7 +105,6 @@ import javax.xml.xpath.XPathFactory;
public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
private static final Logger LOG = LoggerFactory.getLogger(BangleJSDeviceSupport.class);
- private final BroadcastReceiver commandReceiver;
private BluetoothGattCharacteristic rxCharacteristic = null;
private BluetoothGattCharacteristic txCharacteristic = null;
@@ -117,36 +116,83 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
private boolean realtimeStep = false;
private int realtimeHRMInterval = 30*60;
+ // Local Intents - for app manager communication
public static final String BANGLEJS_COMMAND_TX = "banglejs_command_tx";
public static final String BANGLEJS_COMMAND_RX = "banglejs_command_rx";
+ // Global Intents
+ private static final String BANGLE_ACTION_UART_TX = "com.banglejs.uart.tx";
public BangleJSDeviceSupport() {
super(LOG);
addSupportedService(BangleJSConstants.UUID_SERVICE_NORDIC_UART);
+ registerLocalIntents();
+ registerGlobalIntents();
+ }
+
+ private void registerLocalIntents() {
IntentFilter commandFilter = new IntentFilter();
commandFilter.addAction(BANGLEJS_COMMAND_TX);
- commandReceiver = new BroadcastReceiver() {
+ BroadcastReceiver commandReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- switch (intent.getAction()) {
- case BANGLEJS_COMMAND_TX: {
- String data = String.valueOf(intent.getExtras().get("DATA"));
- try {
- TransactionBuilder builder = performInitialized("TX");
- uartTx(builder, data);
- builder.queue(getQueue());
- } catch (IOException e) {
- GB.toast(getContext(), "Error in TX: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
+ switch (intent.getAction()) {
+ case BANGLEJS_COMMAND_TX: {
+ String data = String.valueOf(intent.getExtras().get("DATA"));
+ try {
+ TransactionBuilder builder = performInitialized("TX");
+ uartTx(builder, data);
+ builder.queue(getQueue());
+ } catch (IOException e) {
+ GB.toast(getContext(), "Error in TX: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
+ }
+ break;
}
- break;
}
}
- }
};
LocalBroadcastManager.getInstance(GBApplication.getContext()).registerReceiver(commandReceiver, commandFilter);
}
+ private void registerGlobalIntents() {
+ IntentFilter commandFilter = new IntentFilter();
+ commandFilter.addAction(BANGLE_ACTION_UART_TX);
+ BroadcastReceiver commandReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ switch (intent.getAction()) {
+ case BANGLE_ACTION_UART_TX: {
+ /* In Tasker:
+ Action: com.banglejs.uart.tx
+ Cat: None
+ Extra: line:Terminal.println(%avariable)
+ Target: Broadcast Receiver
+
+ Variable: Number, Configure on Import, NOT structured, Value set, Nothing Exported, NOT Same as value
+ */
+ Prefs devicePrefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()));
+ if (!devicePrefs.getBoolean(PREF_DEVICE_INTENTS, false)) return;
+ String data = intent.getStringExtra("line");
+ if (data==null) {
+ GB.toast(getContext(), "UART TX Intent, but no 'line' supplied", Toast.LENGTH_LONG, GB.ERROR);
+ return;
+ }
+ if (!data.endsWith("\n")) data += "\n";
+ try {
+ TransactionBuilder builder = performInitialized("TX");
+ uartTx(builder, data);
+ builder.queue(getQueue());
+ } catch (IOException e) {
+ GB.toast(getContext(), "Error in TX: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
+ }
+ break;
+ }
+ }
+ }
+ };
+ GBApplication.getContext().registerReceiver(commandReceiver, commandFilter);
+ }
+
@Override
protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
LOG.info("Initializing");
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index a0f99796e..e4c53899b 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -269,7 +269,7 @@
Allow Internet Access
Allow apps on this device to access the internet
Allow Intents
- Allow apps on this device to send Android Intents
+ Allow Bangle.js watch apps to send Android Intents, and allow other apps on Android (like Tasker) to send data to Bangle.js with the com.banglejs.uart.tx Intent.
Enables calendar alerts, even when disconnected
Sync calendar events
Relax firmware checks