From fb44196a0db3259f16af3e098299ea317ee212d4 Mon Sep 17 00:00:00 2001 From: Jens Date: Sun, 28 Mar 2021 23:23:29 +0200 Subject: [PATCH] Notification trigger. --- app/src/apkFlavor/AndroidManifest.xml | 2 +- app/src/fdroidFlavor/AndroidManifest.xml | 2 +- app/src/googlePlayFlavor/AndroidManifest.xml | 2 +- .../java/com/jens/automation2/Action.java | 4 ++-- .../jens/automation2/ActivityManageRule.java | 23 +++++++++++++++++++ .../jens/automation2/ActivityPermissions.java | 23 ++++++++++++------- .../jens/automation2/XmlFileInterface.java | 2 ++ 7 files changed, 45 insertions(+), 13 deletions(-) diff --git a/app/src/apkFlavor/AndroidManifest.xml b/app/src/apkFlavor/AndroidManifest.xml index ff5c92e8..3e0abe21 100644 --- a/app/src/apkFlavor/AndroidManifest.xml +++ b/app/src/apkFlavor/AndroidManifest.xml @@ -210,7 +210,7 @@ diff --git a/app/src/fdroidFlavor/AndroidManifest.xml b/app/src/fdroidFlavor/AndroidManifest.xml index 3ce410e4..a2120b00 100644 --- a/app/src/fdroidFlavor/AndroidManifest.xml +++ b/app/src/fdroidFlavor/AndroidManifest.xml @@ -186,7 +186,7 @@ diff --git a/app/src/googlePlayFlavor/AndroidManifest.xml b/app/src/googlePlayFlavor/AndroidManifest.xml index b434ce27..10d86187 100644 --- a/app/src/googlePlayFlavor/AndroidManifest.xml +++ b/app/src/googlePlayFlavor/AndroidManifest.xml @@ -181,7 +181,7 @@ diff --git a/app/src/main/java/com/jens/automation2/Action.java b/app/src/main/java/com/jens/automation2/Action.java index c4abd2bd..b3fb9cd2 100644 --- a/app/src/main/java/com/jens/automation2/Action.java +++ b/app/src/main/java/com/jens/automation2/Action.java @@ -215,9 +215,9 @@ public class Action { returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.wakeupDevice)); } - else if(this.getAction().equals(Action_Enum.playMusic)) + else if(this.getAction().equals(Action_Enum.playSound)) { - returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.playSound) + " " + getParameter2()); + returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.playSound) + ": " + getParameter2()); } else returnString.append(action.toString()); diff --git a/app/src/main/java/com/jens/automation2/ActivityManageRule.java b/app/src/main/java/com/jens/automation2/ActivityManageRule.java index 377e0270..c258a319 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageRule.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageRule.java @@ -1255,6 +1255,29 @@ public class ActivityManageRule extends Activity this.refreshActionList(); } } + else if(requestCode == requestCodeActionPlaySoundAdd) + { + if(resultCode == RESULT_OK) + { + newAction.setParameter1(data.getBooleanExtra("actionParameter1", false)); + newAction.setParameter2(String.valueOf(data.getIntExtra("actionParameter2", 0))); + ruleToEdit.getActionSet().add(newAction); + this.refreshActionList(); + } + } + else if(requestCode == requestCodeActionPlaySoundEdit) + { + if(resultCode == RESULT_OK) + { + if(data.hasExtra("actionParameter1")) + ruleToEdit.getActionSet().get(editIndex).setParameter1(data.getBooleanExtra("actionParameter1", false)); + + if(data.hasExtra("actionParameter2")) + ruleToEdit.getActionSet().get(editIndex).setParameter2(String.valueOf(data.getIntExtra("actionParameter2", 0))); + + this.refreshActionList(); + } + } //TODO: Check with has data been changed or something like that. /*try diff --git a/app/src/main/java/com/jens/automation2/ActivityPermissions.java b/app/src/main/java/com/jens/automation2/ActivityPermissions.java index eef0b285..ff1b31ff 100644 --- a/app/src/main/java/com/jens/automation2/ActivityPermissions.java +++ b/app/src/main/java/com/jens/automation2/ActivityPermissions.java @@ -1444,14 +1444,21 @@ public class ActivityPermissions extends Activity public static Boolean verifyNotificationPermission() { - String theList = android.provider.Settings.Secure.getString(Miscellaneous.getAnyContext().getContentResolver(), "enabled_notification_listeners"); - String[] theListList = theList.split(":"); - String me = (new ComponentName(Miscellaneous.getAnyContext(), NotificationListener.class)).flattenToString(); - for ( String next : theListList ) + try { - if ( me.equals(next) ) - return true; + String theList = android.provider.Settings.Secure.getString(Miscellaneous.getAnyContext().getContentResolver(), "enabled_notification_listeners"); + String[] theListList = theList.split(":"); + String me = (new ComponentName(Miscellaneous.getAnyContext(), NotificationListener.class)).flattenToString(); + for (String next : theListList) + { + if (me.equals(next)) + return true; + } + return false; + } + catch(Exception e) + { + return false; } - return false; } -} +} \ No newline at end of file diff --git a/app/src/main/java/com/jens/automation2/XmlFileInterface.java b/app/src/main/java/com/jens/automation2/XmlFileInterface.java index dab6d995..4781cb19 100644 --- a/app/src/main/java/com/jens/automation2/XmlFileInterface.java +++ b/app/src/main/java/com/jens/automation2/XmlFileInterface.java @@ -899,6 +899,8 @@ public class XmlFileInterface newTrigger.setTriggerType(Trigger_Enum.bluetoothConnection); else if(triggerEventString.equals("headsetPlugged")) newTrigger.setTriggerType(Trigger_Enum.headsetPlugged); + else if(triggerEventString.equals("notification")) + newTrigger.setTriggerType(Trigger_Enum.notification); } else if (name.equals("TriggerParameter1")) {