close notification with button

This commit is contained in:
jens 2022-07-09 14:22:33 +02:00
parent 922807d903
commit 53e62068a5
3 changed files with 30 additions and 66 deletions

2
.gitignore vendored
View File

@ -145,7 +145,7 @@ fabric.properties
# End of https://www.toptal.com/developers/gitignore/api/androidstudio # End of https://www.toptal.com/developers/gitignore/api/androidstudio
output-metadata.json
/app/app-release.apk /app/app-release.apk
Automation_settings.xml Automation_settings.xml
/app/googlePlayFlavor/ /app/googlePlayFlavor/

View File

@ -1,20 +0,0 @@
{
"version": 3,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "com.jens.automation2",
"variantName": "googlePlayFlavorRelease",
"elements": [
{
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 121,
"versionName": "1.7.6-googlePlay",
"outputFile": "app-googlePlayFlavor-release.apk"
}
],
"elementType": "File"
}

View File

@ -2,6 +2,7 @@ package com.jens.automation2.receivers;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Notification; import android.app.Notification;
import android.app.PendingIntent;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.os.Build; import android.os.Build;
@ -149,51 +150,6 @@ public class NotificationListener extends NotificationListenerService// implemen
return returnNotification; return returnNotification;
} }
/*@Override
public void startListener(AutomationService automationService)
{
if(instance == null)
instance = new NotificationListener();
if(notificationReceiverIntentFilter == null)
{
notificationReceiverIntentFilter = new IntentFilter();
notificationReceiverIntentFilter.addAction("android.service.notification.NotificationListenerService");
}
try
{
if(!listenerRunning)
{
Miscellaneous.logEvent("i", "NotificationListener", "Starting NotificationListener", 4);
listenerRunning = true;
AutomationService.getInstance().registerReceiver(instance, notificationReceiverIntentFilter);
}
}
catch(Exception ex)
{
Miscellaneous.logEvent("e", "BluetoothReceiver", "Error starting BluetoothReceiver: " + Log.getStackTraceString(ex), 3);
}
}
@Override
public void stopListener(AutomationService automationService)
{
}
@Override
public boolean isListenerRunning()
{
return false;
}
@Override
public Trigger.Trigger_Enum[] getMonitoredTrigger()
{
return new Trigger.Trigger_Enum[0];
}*/
public static class SimpleNotification public static class SimpleNotification
{ {
boolean created; boolean created;
@ -283,4 +239,32 @@ public class NotificationListener extends NotificationListenerService// implemen
cancelNotification(sbn.getKey()); cancelNotification(sbn.getKey());
} }
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public void clickNotificationButton(StatusBarNotification sbn, String buttonText)
{
boolean buttonFound = false;
for (Notification.Action a : sbn.getNotification().actions)
{
if(a.toString().equalsIgnoreCase(buttonText))
{
if(!buttonFound)
buttonFound = true;
try
{
Miscellaneous.logEvent("w", "clickNotificationButton()", "Pressing button with text \"" + a.title.toString() + "\".", 2);
a.actionIntent.send();
}
catch (PendingIntent.CanceledException e)
{
Miscellaneous.logEvent("w", "clickNotificationButton()", Log.getStackTraceString(e), 2);
}
}
}
if(!buttonFound)
Miscellaneous.logEvent("w", "clickNotificationButton()", "Button with text \n" + buttonText + "\n could not found.", 2);
}
} }