forked from jens/Automation
stacked notification almost fixed
This commit is contained in:
parent
5a7cbfcdc9
commit
dc35c8b7fb
@ -1,11 +1,14 @@
|
|||||||
package com.jens.automation2;
|
package com.jens.automation2;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.Notification;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
import android.os.Parcelable;
|
||||||
import android.service.notification.StatusBarNotification;
|
import android.service.notification.StatusBarNotification;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -34,6 +37,8 @@ import static com.jens.automation2.Trigger.triggerParameter2Split;
|
|||||||
import static com.jens.automation2.receivers.NotificationListener.EXTRA_TEXT;
|
import static com.jens.automation2.receivers.NotificationListener.EXTRA_TEXT;
|
||||||
import static com.jens.automation2.receivers.NotificationListener.EXTRA_TITLE;
|
import static com.jens.automation2.receivers.NotificationListener.EXTRA_TITLE;
|
||||||
|
|
||||||
|
import androidx.core.app.NotificationCompat;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
|
||||||
@ -796,13 +801,13 @@ public class Rule implements Comparable<Rule>
|
|||||||
|
|
||||||
String myApp = params[0];
|
String myApp = params[0];
|
||||||
String myTitleDir = params[1];
|
String myTitleDir = params[1];
|
||||||
String myTitle = params[2];
|
String requiredTitle = params[2];
|
||||||
String myTextDir = params[3];
|
String myTextDir = params[3];
|
||||||
String myText;
|
String requiredText;
|
||||||
if (params.length >= 5)
|
if (params.length >= 5)
|
||||||
myText = params[4];
|
requiredText = params[4];
|
||||||
else
|
else
|
||||||
myText = "";
|
requiredText = "";
|
||||||
|
|
||||||
if(oneTrigger.getTriggerParameter())
|
if(oneTrigger.getTriggerParameter())
|
||||||
{
|
{
|
||||||
@ -815,8 +820,8 @@ public class Rule implements Comparable<Rule>
|
|||||||
if(getLastExecution() == null || sbn.getPostTime() > this.lastExecution.getTimeInMillis())
|
if(getLastExecution() == null || sbn.getPostTime() > this.lastExecution.getTimeInMillis())
|
||||||
{
|
{
|
||||||
String notificationApp = sbn.getPackageName();
|
String notificationApp = sbn.getPackageName();
|
||||||
String notificationTitle = sbn.getNotification().extras.getString(EXTRA_TITLE);
|
String notificationTitle = null;
|
||||||
String notificationText = sbn.getNotification().extras.getString(EXTRA_TEXT);
|
String notificationText = null;
|
||||||
|
|
||||||
Miscellaneous.logEvent("i", "NotificationCheck", "Checking if this notification matches our rule " + this.getName() + ". App: " + notificationApp + ", title: " + notificationTitle + ", text: " + notificationText, 5);
|
Miscellaneous.logEvent("i", "NotificationCheck", "Checking if this notification matches our rule " + this.getName() + ". App: " + notificationApp + ", title: " + notificationTitle + ", text: " + notificationText, 5);
|
||||||
|
|
||||||
@ -829,27 +834,44 @@ public class Rule implements Comparable<Rule>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!StringUtils.isEmpty(myTitle))
|
/*
|
||||||
{
|
If there are multiple notifications ("stacked") this will fail.
|
||||||
if (!Miscellaneous.compare(myTitleDir, myTitle, notificationTitle))
|
https://stackoverflow.com/questions/28047767/notificationlistenerservice-not-reading-text-of-stacked-notifications
|
||||||
{
|
*/
|
||||||
Miscellaneous.logEvent("i", "NotificationCheck", "Notification title does not match rule.", 5);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
Miscellaneous.logEvent("i", "NotificationCheck", "A required title for a notification trigger was not specified.", 5);
|
|
||||||
|
|
||||||
if (!StringUtils.isEmpty(myText))
|
Bundle extras = sbn.getNotification().extras;
|
||||||
{
|
if (extras.containsKey(EXTRA_TITLE))
|
||||||
if (!Miscellaneous.compare(myTextDir, myText, notificationText))
|
notificationTitle = sbn.getNotification().extras.getString(EXTRA_TITLE);
|
||||||
|
|
||||||
|
if (extras.containsKey(EXTRA_TEXT))
|
||||||
|
notificationText = sbn.getNotification().extras.getString(EXTRA_TEXT);
|
||||||
|
|
||||||
|
// T I T L E
|
||||||
|
|
||||||
|
if (!StringUtils.isEmpty(requiredTitle))
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "NotificationCheck", "Notification text does not match rule.", 5);
|
if (!Miscellaneous.compare(myTitleDir, requiredTitle, notificationTitle))
|
||||||
continue;
|
{
|
||||||
|
Miscellaneous.logEvent("i", "NotificationCheck", "Notification title does not match rule.", 5);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
Miscellaneous.logEvent("i", "NotificationCheck", "A required title for a notification trigger was not specified.", 5);
|
||||||
Miscellaneous.logEvent("i", "NotificationCheck", "A required text for a notification trigger was not specified.", 5);
|
|
||||||
|
// T E X T
|
||||||
|
|
||||||
|
if (!StringUtils.isEmpty(requiredText))
|
||||||
|
{
|
||||||
|
if (!Miscellaneous.compare(myTextDir, requiredText, notificationText))
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "NotificationCheck", "Notification text does not match rule.", 5);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Miscellaneous.logEvent("i", "NotificationCheck", "A required text for a notification trigger was not specified.", 5);
|
||||||
|
// }
|
||||||
|
|
||||||
foundMatch = true;
|
foundMatch = true;
|
||||||
break;
|
break;
|
||||||
@ -877,15 +899,15 @@ public class Rule implements Comparable<Rule>
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myTitle.length() > 0)
|
if (requiredTitle.length() > 0)
|
||||||
{
|
{
|
||||||
if (!Miscellaneous.compare(myTitleDir, title, myTitle))
|
if (!Miscellaneous.compare(myTitleDir, title, requiredTitle))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myText.length() > 0)
|
if (requiredText.length() > 0)
|
||||||
{
|
{
|
||||||
if (!Miscellaneous.compare(myTextDir, text, myText))
|
if (!Miscellaneous.compare(myTextDir, text, requiredText))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ public class ActivityManageTriggerWifi extends Activity
|
|||||||
wifiList.add(wifi.SSID.replaceAll("\"+$", "").replaceAll("^\"+", ""));
|
wifiList.add(wifi.SSID.replaceAll("\"+$", "").replaceAll("^\"+", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wifiList.size() > 0)
|
if (wifiList.size() > 0)
|
||||||
{
|
{
|
||||||
spinnerWifiList.setEnabled(true);
|
spinnerWifiList.setEnabled(true);
|
||||||
Collections.sort(wifiList);
|
Collections.sort(wifiList);
|
||||||
|
@ -447,6 +447,14 @@ public class Miscellaneous extends Service
|
|||||||
|
|
||||||
public static boolean compare(String direction, String needle, String haystack)
|
public static boolean compare(String direction, String needle, String haystack)
|
||||||
{
|
{
|
||||||
|
// If only one of needle or haystack is null
|
||||||
|
if(
|
||||||
|
(needle == null && haystack != null)
|
||||||
|
||
|
||||||
|
(needle != null && haystack == null)
|
||||||
|
)
|
||||||
|
return false;
|
||||||
|
|
||||||
switch(direction)
|
switch(direction)
|
||||||
{
|
{
|
||||||
case Trigger.directionEquals:
|
case Trigger.directionEquals:
|
||||||
|
Loading…
Reference in New Issue
Block a user