close notification action
This commit is contained in:
parent
246a02371a
commit
98185a79df
@ -147,7 +147,7 @@
|
|||||||
<activity android:name=".ActivityDisplayLongMessage" />
|
<activity android:name=".ActivityDisplayLongMessage" />
|
||||||
<activity android:name=".ActivityManageActionSendTextMessage" />
|
<activity android:name=".ActivityManageActionSendTextMessage" />
|
||||||
<activity android:name=".ActivityManageActionPlaySound" />
|
<activity android:name=".ActivityManageActionPlaySound" />
|
||||||
<activity android:name=".ActivityManageActionCloseNotification"
|
<activity android:name=".ActivityManageActionCloseNotification" />
|
||||||
<activity android:name=".ActivityManageTriggerProfile" />
|
<activity android:name=".ActivityManageTriggerProfile" />
|
||||||
<activity android:name=".ActivityManageTriggerTimeFrame" />
|
<activity android:name=".ActivityManageTriggerTimeFrame" />
|
||||||
<activity android:name=".ActivityMaintenance" />
|
<activity android:name=".ActivityMaintenance" />
|
||||||
|
@ -145,6 +145,7 @@
|
|||||||
<activity android:name=".ActivityDisplayLongMessage" />
|
<activity android:name=".ActivityDisplayLongMessage" />
|
||||||
<activity android:name=".ActivityManageActionSendTextMessage" />
|
<activity android:name=".ActivityManageActionSendTextMessage" />
|
||||||
<activity android:name=".ActivityManageActionPlaySound" />
|
<activity android:name=".ActivityManageActionPlaySound" />
|
||||||
|
<activity android:name=".ActivityManageActionCloseNotification" />
|
||||||
<activity android:name=".ActivityManageTriggerProfile" />
|
<activity android:name=".ActivityManageTriggerProfile" />
|
||||||
<activity android:name=".ActivityManageTriggerTimeFrame" />
|
<activity android:name=".ActivityManageTriggerTimeFrame" />
|
||||||
<activity android:name=".ActivityMaintenance" />
|
<activity android:name=".ActivityMaintenance" />
|
||||||
|
@ -139,6 +139,7 @@
|
|||||||
<activity android:name=".ActivityDisplayLongMessage" />
|
<activity android:name=".ActivityDisplayLongMessage" />
|
||||||
<activity android:name=".ActivityManageActionSendTextMessage" />
|
<activity android:name=".ActivityManageActionSendTextMessage" />
|
||||||
<activity android:name=".ActivityManageActionPlaySound" />
|
<activity android:name=".ActivityManageActionPlaySound" />
|
||||||
|
<activity android:name=".ActivityManageActionCloseNotification" />
|
||||||
<activity android:name=".ActivityManageTriggerProfile" />
|
<activity android:name=".ActivityManageTriggerProfile" />
|
||||||
<activity android:name=".ActivityManageTriggerTimeFrame" />
|
<activity android:name=".ActivityManageTriggerTimeFrame" />
|
||||||
<activity android:name=".ActivityMaintenance" />
|
<activity android:name=".ActivityMaintenance" />
|
||||||
|
@ -112,6 +112,8 @@ public class Action
|
|||||||
return context.getResources().getString(R.string.setScreenBrightness);
|
return context.getResources().getString(R.string.setScreenBrightness);
|
||||||
case createNotification:
|
case createNotification:
|
||||||
return context.getResources().getString(R.string.createNotification);
|
return context.getResources().getString(R.string.createNotification);
|
||||||
|
case closeNotification:
|
||||||
|
return context.getResources().getString(R.string.closeNotifications);
|
||||||
default:
|
default:
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package com.jens.automation2;
|
package com.jens.automation2;
|
||||||
|
|
||||||
|
import static com.jens.automation2.receivers.NotificationListener.EXTRA_TEXT;
|
||||||
|
import static com.jens.automation2.receivers.NotificationListener.EXTRA_TITLE;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
@ -19,6 +22,7 @@ import android.net.ConnectivityManager;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.PowerManager.WakeLock;
|
import android.os.PowerManager.WakeLock;
|
||||||
import android.os.VibrationEffect;
|
import android.os.VibrationEffect;
|
||||||
@ -37,7 +41,9 @@ import com.jens.automation2.actions.wifi_router.MyOnStartTetheringCallback;
|
|||||||
import com.jens.automation2.actions.wifi_router.MyOreoWifiManager;
|
import com.jens.automation2.actions.wifi_router.MyOreoWifiManager;
|
||||||
import com.jens.automation2.location.WifiBroadcastReceiver;
|
import com.jens.automation2.location.WifiBroadcastReceiver;
|
||||||
import com.jens.automation2.receivers.ConnectivityReceiver;
|
import com.jens.automation2.receivers.ConnectivityReceiver;
|
||||||
|
import com.jens.automation2.receivers.NotificationListener;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.conn.ClientConnectionManager;
|
import org.apache.http.conn.ClientConnectionManager;
|
||||||
import org.apache.http.conn.scheme.Scheme;
|
import org.apache.http.conn.scheme.Scheme;
|
||||||
@ -106,7 +112,85 @@ public class Actions
|
|||||||
NotificationManager nm = (NotificationManager) Miscellaneous.getAnyContext().getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager nm = (NotificationManager) Miscellaneous.getAnyContext().getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
for(StatusBarNotification n : nm.getActiveNotifications())
|
for(StatusBarNotification n : nm.getActiveNotifications())
|
||||||
{
|
{
|
||||||
n.
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
|
||||||
|
{
|
||||||
|
String[] params = action.getParameter2().split(Action.actionParameter2Split);
|
||||||
|
|
||||||
|
String myApp = params[0];
|
||||||
|
String myTitleDir = params[1];
|
||||||
|
String requiredTitle = params[2];
|
||||||
|
String myTextDir = params[3];
|
||||||
|
String requiredText;
|
||||||
|
if (params.length >= 5)
|
||||||
|
requiredText = params[4];
|
||||||
|
else
|
||||||
|
requiredText = "";
|
||||||
|
|
||||||
|
for (StatusBarNotification sbn : NotificationListener.getInstance().getActiveNotifications())
|
||||||
|
{
|
||||||
|
String notificationApp = sbn.getPackageName();
|
||||||
|
String notificationTitle = null;
|
||||||
|
String notificationText = null;
|
||||||
|
|
||||||
|
Miscellaneous.logEvent("i", "NotificationCloseCheck", "Checking if this notification matches our rule " + action.getParentRule().getName() + ". App: " + notificationApp + ", title: " + notificationTitle + ", text: " + notificationText, 5);
|
||||||
|
|
||||||
|
if (!myApp.equals("-1"))
|
||||||
|
{
|
||||||
|
if (!notificationApp.equalsIgnoreCase(myApp))
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "NotificationCloseCheck", "Notification app name does not match rule.", 5);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(myApp.equals(BuildConfig.APPLICATION_ID))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
If there are multiple notifications ("stacked") title or text might be null:
|
||||||
|
https://stackoverflow.com/questions/28047767/notificationlistenerservice-not-reading-text-of-stacked-notifications
|
||||||
|
*/
|
||||||
|
|
||||||
|
Bundle extras = sbn.getNotification().extras;
|
||||||
|
|
||||||
|
// T I T L E
|
||||||
|
if (extras.containsKey(EXTRA_TITLE))
|
||||||
|
notificationTitle = sbn.getNotification().extras.getString(EXTRA_TITLE);
|
||||||
|
|
||||||
|
if (!StringUtils.isEmpty(requiredTitle))
|
||||||
|
{
|
||||||
|
if (!Miscellaneous.compare(myTitleDir, requiredTitle, notificationTitle))
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "NotificationCloseCheck", "Notification title does not match rule.", 5);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// T E X T
|
||||||
|
|
||||||
|
if (extras.containsKey(EXTRA_TEXT))
|
||||||
|
notificationText = sbn.getNotification().extras.getString(EXTRA_TEXT);
|
||||||
|
|
||||||
|
if (!StringUtils.isEmpty(requiredText))
|
||||||
|
{
|
||||||
|
if (!Miscellaneous.compare(myTextDir, requiredText, notificationText))
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "NotificationCloseCheck", "Notification text does not match rule.", 5);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Miscellaneous.logEvent("i", "NotificationCloseCheck", "All criteria matches. Closing notification: " + sbn.getNotification().toString(), 3);
|
||||||
|
if(NotificationListener.getInstance() != null)
|
||||||
|
NotificationListener.getInstance().dismissNotification(sbn);
|
||||||
|
else
|
||||||
|
Miscellaneous.logEvent("i", "NotificationCloseCheck", "NotificationListener instance is null. Can\'t close notification.", 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,8 @@ import android.widget.EditText;
|
|||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@ -38,15 +40,13 @@ public class ActivityManageActionCloseNotification extends Activity
|
|||||||
public static final String intentNameNotificationText = "text";
|
public static final String intentNameNotificationText = "text";
|
||||||
public static final String intentNameNotificationDirection = "direction";
|
public static final String intentNameNotificationDirection = "direction";
|
||||||
|
|
||||||
public static Trigger editedNotificationTrigger;
|
|
||||||
boolean edit = false;
|
boolean edit = false;
|
||||||
ProgressDialog progressDialog = null;
|
ProgressDialog progressDialog = null;
|
||||||
|
|
||||||
EditText etNotificationTitle, etNotificationText;
|
EditText etNotificationTitle, etNotificationText;
|
||||||
Button bSelectApp, bSaveTriggerNotification;
|
Button bSelectApp, bSaveActionCloseNotification;
|
||||||
Spinner spinnerTitleDirection, spinnerTextDirection;
|
Spinner spinnerTitleDirection, spinnerTextDirection;
|
||||||
TextView tvSelectedApplication;
|
TextView tvSelectedApplication;
|
||||||
CheckBox chkNotificationDirection;
|
|
||||||
|
|
||||||
private static List<PackageInfo> pInfos = null;
|
private static List<PackageInfo> pInfos = null;
|
||||||
public static Trigger resultingTrigger;
|
public static Trigger resultingTrigger;
|
||||||
@ -258,16 +258,15 @@ public class ActivityManageActionCloseNotification extends Activity
|
|||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_manage_trigger_notification);
|
setContentView(R.layout.activity_manage_action_close_notification);
|
||||||
|
|
||||||
etNotificationTitle = (EditText)findViewById(R.id.etNotificationTitle);
|
etNotificationTitle = (EditText)findViewById(R.id.etNotificationTitle);
|
||||||
etNotificationText = (EditText)findViewById(R.id.etNotificationText);
|
etNotificationText = (EditText)findViewById(R.id.etNotificationText);
|
||||||
bSelectApp = (Button)findViewById(R.id.bSelectApp);
|
bSelectApp = (Button)findViewById(R.id.bSelectApp);
|
||||||
bSaveTriggerNotification = (Button)findViewById(R.id.bSaveTriggerNotification);
|
bSaveActionCloseNotification = (Button)findViewById(R.id.bSaveActionCloseNotification);
|
||||||
spinnerTitleDirection = (Spinner)findViewById(R.id.spinnerTitleDirection);
|
spinnerTitleDirection = (Spinner)findViewById(R.id.spinnerTitleDirection);
|
||||||
spinnerTextDirection = (Spinner)findViewById(R.id.spinnerTextDirection);
|
spinnerTextDirection = (Spinner)findViewById(R.id.spinnerTextDirection);
|
||||||
tvSelectedApplication = (TextView)findViewById(R.id.etActivityOrActionPath);
|
tvSelectedApplication = (TextView)findViewById(R.id.etActivityOrActionPath);
|
||||||
chkNotificationDirection = (CheckBox)findViewById(R.id.chkNotificationDirection);
|
|
||||||
|
|
||||||
directions = new String[] {
|
directions = new String[] {
|
||||||
getResources().getString(R.string.directionStringEquals),
|
getResources().getString(R.string.directionStringEquals),
|
||||||
@ -293,19 +292,7 @@ public class ActivityManageActionCloseNotification extends Activity
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
chkNotificationDirection.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
bSaveActionCloseNotification.setOnClickListener(new OnClickListener()
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
|
||||||
{
|
|
||||||
if(isChecked)
|
|
||||||
chkNotificationDirection.setText(getResources().getString(R.string.notificationAppears));
|
|
||||||
else
|
|
||||||
chkNotificationDirection.setText(getResources().getString(R.string.notificationDisappears));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
bSaveTriggerNotification.setOnClickListener(new OnClickListener()
|
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v)
|
public void onClick(View v)
|
||||||
@ -321,22 +308,29 @@ public class ActivityManageActionCloseNotification extends Activity
|
|||||||
String textDir = Trigger.getMatchCode(spinnerTextDirection.getSelectedItem().toString());
|
String textDir = Trigger.getMatchCode(spinnerTextDirection.getSelectedItem().toString());
|
||||||
String text = etNotificationText.getText().toString();
|
String text = etNotificationText.getText().toString();
|
||||||
|
|
||||||
|
Intent responseData = new Intent();
|
||||||
if(edit)
|
if(edit)
|
||||||
{
|
{
|
||||||
editedNotificationTrigger.setTriggerParameter(chkNotificationDirection.isChecked());
|
// editedNotificationAction.setTriggerParameter(chkNotificationDirection.isChecked());
|
||||||
editedNotificationTrigger.setTriggerParameter2(app + triggerParameter2Split + titleDir + triggerParameter2Split + title + triggerParameter2Split + textDir + triggerParameter2Split + text);
|
responseData.putExtra(ActivityManageRule.intentNameActionParameter2, app + Action.actionParameter2Split + titleDir + Action.actionParameter2Split + title + Action.actionParameter2Split + textDir + Action.actionParameter2Split + text);
|
||||||
ActivityManageActionCloseNotification.this.setResult(RESULT_OK);
|
ActivityManageActionCloseNotification.this.setResult(RESULT_OK, responseData);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Intent data = new Intent();
|
// data.putExtra(intentNameNotificationDirection, chkNotificationDirection.isChecked());
|
||||||
data.putExtra(intentNameNotificationDirection, chkNotificationDirection.isChecked());
|
responseData.putExtra(ActivityManageRule.intentNameActionParameter2,
|
||||||
data.putExtra(intentNameNotificationApp, app);
|
app + Action.actionParameter2Split +
|
||||||
data.putExtra(intentNameNotificationTitleDir, titleDir);
|
titleDir + Action.actionParameter2Split +
|
||||||
data.putExtra(intentNameNotificationTitle, title);
|
title + Action.actionParameter2Split +
|
||||||
data.putExtra(intentNameNotificationTextDir, textDir);
|
textDir + Action.actionParameter2Split +
|
||||||
data.putExtra(intentNameNotificationText, text);
|
text
|
||||||
ActivityManageActionCloseNotification.this.setResult(RESULT_OK, data);
|
);
|
||||||
|
// data.putExtra(intentNameNotificationApp, app);
|
||||||
|
// data.putExtra(intentNameNotificationTitleDir, titleDir);
|
||||||
|
// data.putExtra(intentNameNotificationTitle, title);
|
||||||
|
// data.putExtra(intentNameNotificationTextDir, textDir);
|
||||||
|
// data.putExtra(intentNameNotificationText, text);
|
||||||
|
ActivityManageActionCloseNotification.this.setResult(RESULT_OK, responseData);
|
||||||
}
|
}
|
||||||
|
|
||||||
finish();
|
finish();
|
||||||
@ -344,18 +338,16 @@ public class ActivityManageActionCloseNotification extends Activity
|
|||||||
});
|
});
|
||||||
|
|
||||||
Intent i = getIntent();
|
Intent i = getIntent();
|
||||||
if(i.getBooleanExtra("edit", false) == true)
|
if(!StringUtils.isBlank(i.getStringExtra(ActivityManageRule.intentNameActionParameter2)))
|
||||||
{
|
{
|
||||||
edit = true;
|
edit = true;
|
||||||
loadValuesIntoGui();
|
loadValuesIntoGui(i.getStringExtra(ActivityManageRule.intentNameActionParameter2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadValuesIntoGui()
|
private void loadValuesIntoGui(String param)
|
||||||
{
|
{
|
||||||
chkNotificationDirection.setChecked(editedNotificationTrigger.getTriggerParameter());
|
String[] params = param.split(Action.actionParameter2Split);
|
||||||
|
|
||||||
String[] params = editedNotificationTrigger.getTriggerParameter2().split(triggerParameter2Split);
|
|
||||||
|
|
||||||
String app = params[0];
|
String app = params[0];
|
||||||
String titleDir = params[1];
|
String titleDir = params[1];
|
||||||
|
@ -1589,6 +1589,8 @@ public class ActivityManageRule extends Activity
|
|||||||
items.add(new Item(typesLong[i].toString(), R.drawable.vibrate));
|
items.add(new Item(typesLong[i].toString(), R.drawable.vibrate));
|
||||||
else if(types[i].toString().equals(Action_Enum.createNotification.toString()))
|
else if(types[i].toString().equals(Action_Enum.createNotification.toString()))
|
||||||
items.add(new Item(typesLong[i].toString(), R.drawable.notification));
|
items.add(new Item(typesLong[i].toString(), R.drawable.notification));
|
||||||
|
else if(types[i].toString().equals(Action_Enum.closeNotification.toString()))
|
||||||
|
items.add(new Item(typesLong[i].toString(), R.drawable.notification));
|
||||||
else if(types[i].toString().equals(Action_Enum.sendTextMessage.toString()))
|
else if(types[i].toString().equals(Action_Enum.sendTextMessage.toString()))
|
||||||
{
|
{
|
||||||
// if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageSpecificRule.this, "android.permission.SEND_SMS") && !Miscellaneous.isGooglePlayInstalled(ActivityManageSpecificRule.this))
|
// if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageSpecificRule.this, "android.permission.SEND_SMS") && !Miscellaneous.isGooglePlayInstalled(ActivityManageSpecificRule.this))
|
||||||
|
@ -263,7 +263,7 @@ public class ActivityManageTriggerNotification extends Activity
|
|||||||
etNotificationTitle = (EditText)findViewById(R.id.etNotificationTitle);
|
etNotificationTitle = (EditText)findViewById(R.id.etNotificationTitle);
|
||||||
etNotificationText = (EditText)findViewById(R.id.etNotificationText);
|
etNotificationText = (EditText)findViewById(R.id.etNotificationText);
|
||||||
bSelectApp = (Button)findViewById(R.id.bSelectApp);
|
bSelectApp = (Button)findViewById(R.id.bSelectApp);
|
||||||
bSaveTriggerNotification = (Button)findViewById(R.id.bSaveTriggerNotification);
|
bSaveTriggerNotification = (Button)findViewById(R.id.bSaveActionCloseNotification);
|
||||||
spinnerTitleDirection = (Spinner)findViewById(R.id.spinnerTitleDirection);
|
spinnerTitleDirection = (Spinner)findViewById(R.id.spinnerTitleDirection);
|
||||||
spinnerTextDirection = (Spinner)findViewById(R.id.spinnerTextDirection);
|
spinnerTextDirection = (Spinner)findViewById(R.id.spinnerTextDirection);
|
||||||
tvSelectedApplication = (TextView)findViewById(R.id.etActivityOrActionPath);
|
tvSelectedApplication = (TextView)findViewById(R.id.etActivityOrActionPath);
|
||||||
|
@ -649,6 +649,9 @@ public class ActivityPermissions extends Activity
|
|||||||
case playSound:
|
case playSound:
|
||||||
addToArrayListUnique(Manifest.permission.READ_EXTERNAL_STORAGE, requiredPermissions);
|
addToArrayListUnique(Manifest.permission.READ_EXTERNAL_STORAGE, requiredPermissions);
|
||||||
break;
|
break;
|
||||||
|
case closeNotification:
|
||||||
|
addToArrayListUnique(Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE, requiredPermissions);
|
||||||
|
break;
|
||||||
case turnScreenOnOrOff:
|
case turnScreenOnOrOff:
|
||||||
if(action.getParameter1())
|
if(action.getParameter1())
|
||||||
addToArrayListUnique(Manifest.permission.WAKE_LOCK, requiredPermissions);
|
addToArrayListUnique(Manifest.permission.WAKE_LOCK, requiredPermissions);
|
||||||
|
@ -628,6 +628,8 @@ public class Miscellaneous extends Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(source.contains("[notificationTitle]"))
|
if(source.contains("[notificationTitle]"))
|
||||||
|
{
|
||||||
|
if(NotificationListener.getLastNotification() != null)
|
||||||
{
|
{
|
||||||
String notificationTitle = NotificationListener.getLastNotification().getTitle();
|
String notificationTitle = NotificationListener.getLastNotification().getTitle();
|
||||||
|
|
||||||
@ -635,12 +637,20 @@ public class Miscellaneous extends Service
|
|||||||
source = source.replace("[notificationTitle]", notificationTitle);
|
source = source.replace("[notificationTitle]", notificationTitle);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
source = source.replace("notificationTitle unknown", notificationTitle);
|
source = source.replace("[notificationTitle]", "notificationTitle unknown");
|
||||||
Miscellaneous.logEvent("w", "Variable replacement", "notificationTitle was empty.", 3);
|
Miscellaneous.logEvent("w", "Variable replacement", "notificationTitle was empty.", 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
source = source.replace("[notificationTitle]", "notificationTitle unknown");
|
||||||
|
Miscellaneous.logEvent("w", "Variable replacement", "lastNotification was empty.", 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(source.contains("[notificationText]"))
|
if(source.contains("[notificationText]"))
|
||||||
|
{
|
||||||
|
if(NotificationListener.getLastNotification() != null)
|
||||||
{
|
{
|
||||||
String notificationText = NotificationListener.getLastNotification().getText();
|
String notificationText = NotificationListener.getLastNotification().getText();
|
||||||
|
|
||||||
@ -648,10 +658,16 @@ public class Miscellaneous extends Service
|
|||||||
source = source.replace("[notificationText]", notificationText);
|
source = source.replace("[notificationText]", notificationText);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
source = source.replace("notificationText unknown", notificationText);
|
source = source.replace("[notificationText]", "notificationText unknown");
|
||||||
Miscellaneous.logEvent("w", "Variable replacement", "notificationText was empty.", 3);
|
Miscellaneous.logEvent("w", "Variable replacement", "notificationText was empty.", 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
source = source.replace("[notificationText]", "notificationText unknown");
|
||||||
|
Miscellaneous.logEvent("w", "Variable replacement", "lastNotification was empty.", 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Miscellaneous.logEvent("i", "URL after replace", source);
|
// Miscellaneous.logEvent("i", "URL after replace", source);
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@ public class ReceiverCoordinator
|
|||||||
HeadphoneJackListener.class,
|
HeadphoneJackListener.class,
|
||||||
//NfcReceiver.class,
|
//NfcReceiver.class,
|
||||||
NoiseListener.class,
|
NoiseListener.class,
|
||||||
|
//NotificationListener.class,
|
||||||
PhoneStatusListener.class,
|
PhoneStatusListener.class,
|
||||||
ProcessListener.class,
|
ProcessListener.class,
|
||||||
TimeZoneListener.class
|
TimeZoneListener.class
|
||||||
@ -132,12 +133,6 @@ public class ReceiverCoordinator
|
|||||||
Miscellaneous.logEvent("w", "Error in new model", Log.getStackTraceString(e), 3);
|
Miscellaneous.logEvent("w", "Error in new model", Log.getStackTraceString(e), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if(Settings.useAccelerometerForPositioning && !Miscellaneous.isAndroidEmulator())
|
|
||||||
// {
|
|
||||||
// accelerometerHandler = new AccelerometerHandler();
|
|
||||||
// mySensorActivity = new SensorActivity(this);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// startPhoneStateListener
|
// startPhoneStateListener
|
||||||
PhoneStatusListener.startPhoneStatusListener(AutomationService.getInstance()); // also used to mute anouncements during calls
|
PhoneStatusListener.startPhoneStatusListener(AutomationService.getInstance()); // also used to mute anouncements during calls
|
||||||
|
|
||||||
@ -163,7 +158,7 @@ public class ReceiverCoordinator
|
|||||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.noiseLevel))
|
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.noiseLevel))
|
||||||
NoiseListener.startNoiseListener(AutomationService.getInstance());
|
NoiseListener.startNoiseListener(AutomationService.getInstance());
|
||||||
|
|
||||||
// startNoiseListener
|
// startProcessListener
|
||||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.process_started_stopped))
|
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.process_started_stopped))
|
||||||
ProcessListener.startProcessListener(AutomationService.getInstance());
|
ProcessListener.startProcessListener(AutomationService.getInstance());
|
||||||
|
|
||||||
@ -241,7 +236,7 @@ public class ReceiverCoordinator
|
|||||||
|
|
||||||
// timeFrame -> too inexpensive to shutdown
|
// timeFrame -> too inexpensive to shutdown
|
||||||
|
|
||||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.charging) | Rule.isAnyRuleUsing(Trigger.Trigger_Enum.usb_host_connection) | Rule.isAnyRuleUsing(Trigger.Trigger_Enum.batteryLevel))
|
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.charging) || Rule.isAnyRuleUsing(Trigger.Trigger_Enum.usb_host_connection) || Rule.isAnyRuleUsing(Trigger.Trigger_Enum.batteryLevel))
|
||||||
{
|
{
|
||||||
if(BatteryReceiver.haveAllPermission())
|
if(BatteryReceiver.haveAllPermission())
|
||||||
BatteryReceiver.startBatteryReceiver(AutomationService.getInstance());
|
BatteryReceiver.startBatteryReceiver(AutomationService.getInstance());
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package com.jens.automation2.receivers;
|
package com.jens.automation2.receivers;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.service.notification.NotificationListenerService;
|
import android.service.notification.NotificationListenerService;
|
||||||
import android.service.notification.StatusBarNotification;
|
import android.service.notification.StatusBarNotification;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
|
|
||||||
@ -19,9 +22,10 @@ import java.util.Calendar;
|
|||||||
|
|
||||||
@SuppressLint("OverrideAbstract")
|
@SuppressLint("OverrideAbstract")
|
||||||
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
|
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
|
||||||
public class NotificationListener extends NotificationListenerService
|
public class NotificationListener extends NotificationListenerService// implements AutomationListenerInterface
|
||||||
{
|
{
|
||||||
static Calendar lastResponseToNotification = null;
|
static Calendar lastResponseToNotification = null;
|
||||||
|
static boolean listenerRunning = false;
|
||||||
static NotificationListener instance;
|
static NotificationListener instance;
|
||||||
static SimpleNotification lastNotification = null;
|
static SimpleNotification lastNotification = null;
|
||||||
|
|
||||||
@ -37,6 +41,8 @@ public class NotificationListener extends NotificationListenerService
|
|||||||
// a bitmap to be used instead of the small icon when showing the notification payload
|
// a bitmap to be used instead of the small icon when showing the notification payload
|
||||||
public static final String EXTRA_LARGE_ICON = "android.largeIcon";
|
public static final String EXTRA_LARGE_ICON = "android.largeIcon";
|
||||||
|
|
||||||
|
protected static IntentFilter notificationReceiverIntentFilter = null;
|
||||||
|
|
||||||
public static SimpleNotification getLastNotification()
|
public static SimpleNotification getLastNotification()
|
||||||
{
|
{
|
||||||
return lastNotification;
|
return lastNotification;
|
||||||
@ -78,16 +84,7 @@ public class NotificationListener extends NotificationListenerService
|
|||||||
{
|
{
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT)
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT)
|
||||||
{
|
{
|
||||||
String app = sbn.getPackageName();
|
lastNotification = convertNotificationToSimpleNotification(created, sbn);
|
||||||
String title = sbn.getNotification().extras.getString(EXTRA_TITLE);
|
|
||||||
String text = sbn.getNotification().extras.getString(EXTRA_TEXT);
|
|
||||||
|
|
||||||
lastNotification = new SimpleNotification();
|
|
||||||
lastNotification.publishTime = Miscellaneous.calendarFromLong(sbn.getPostTime());
|
|
||||||
lastNotification.created = created;
|
|
||||||
lastNotification.app = app;
|
|
||||||
lastNotification.title = title;
|
|
||||||
lastNotification.text = text;
|
|
||||||
|
|
||||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.notification);
|
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.notification);
|
||||||
for (int i = 0; i < ruleCandidates.size(); i++)
|
for (int i = 0; i < ruleCandidates.size(); i++)
|
||||||
@ -100,6 +97,68 @@ public class NotificationListener extends NotificationListenerService
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
||||||
|
public static SimpleNotification convertNotificationToSimpleNotification(boolean created, StatusBarNotification input)
|
||||||
|
{
|
||||||
|
String app = input.getPackageName();
|
||||||
|
String title = input.getNotification().extras.getString(EXTRA_TITLE);
|
||||||
|
String text = input.getNotification().extras.getString(EXTRA_TEXT);
|
||||||
|
|
||||||
|
SimpleNotification returnNotification = new SimpleNotification();
|
||||||
|
returnNotification.publishTime = Miscellaneous.calendarFromLong(input.getPostTime());
|
||||||
|
returnNotification.created = created;
|
||||||
|
returnNotification.app = app;
|
||||||
|
returnNotification.title = title;
|
||||||
|
returnNotification.text = text;
|
||||||
|
|
||||||
|
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;
|
||||||
@ -168,4 +227,13 @@ public class NotificationListener extends NotificationListenerService
|
|||||||
{
|
{
|
||||||
super.onListenerDisconnected();
|
super.onListenerDisconnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void dismissNotification(StatusBarNotification sbn)
|
||||||
|
{
|
||||||
|
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
|
||||||
|
cancelNotification(sbn.getPackageName(), sbn.getTag(), sbn.getId());
|
||||||
|
else
|
||||||
|
cancelNotification(sbn.getKey());
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
@ -68,6 +68,14 @@
|
|||||||
android:layout_marginVertical="@dimen/default_margin"
|
android:layout_marginVertical="@dimen/default_margin"
|
||||||
android:background="#aa000000" />
|
android:background="#aa000000" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:text="@string/comparisonCaseInsensitive"
|
||||||
|
android:layout_marginBottom="@dimen/default_margin"/>
|
||||||
|
|
||||||
<TableRow
|
<TableRow
|
||||||
android:layout_marginBottom="@dimen/activity_vertical_margin">
|
android:layout_marginBottom="@dimen/activity_vertical_margin">
|
||||||
|
|
||||||
@ -136,7 +144,7 @@
|
|||||||
</TableLayout>
|
</TableLayout>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/bSaveTriggerNotification"
|
android:id="@+id/bSaveActionCloseNotification"
|
||||||
android:layout_marginTop="@dimen/default_margin"
|
android:layout_marginTop="@dimen/default_margin"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -96,6 +96,13 @@
|
|||||||
android:layout_margin="10dp"
|
android:layout_margin="10dp"
|
||||||
android:layout_marginVertical="@dimen/default_margin"
|
android:layout_marginVertical="@dimen/default_margin"
|
||||||
android:background="#aa000000" />
|
android:background="#aa000000" />
|
||||||
|
<TextView
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:text="@string/comparisonCaseInsensitive"
|
||||||
|
android:layout_marginBottom="@dimen/default_margin"/>
|
||||||
|
|
||||||
<TableRow
|
<TableRow
|
||||||
android:layout_marginBottom="@dimen/activity_vertical_margin">
|
android:layout_marginBottom="@dimen/activity_vertical_margin">
|
||||||
@ -165,7 +172,7 @@
|
|||||||
</TableLayout>
|
</TableLayout>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/bSaveTriggerNotification"
|
android:id="@+id/bSaveActionCloseNotification"
|
||||||
android:layout_marginTop="@dimen/default_margin"
|
android:layout_marginTop="@dimen/default_margin"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -664,4 +664,7 @@
|
|||||||
<string name="info">Info</string>
|
<string name="info">Info</string>
|
||||||
<string name="createNotification">Benachrichtigung erstellen</string>
|
<string name="createNotification">Benachrichtigung erstellen</string>
|
||||||
<string name="profileWasNotFound">Das Profil, das in dieser Regel referenziert wird, existiert scheinbar nicht mehr. Das alphabetisch erste wurde stattdessen ausgewählt.</string>
|
<string name="profileWasNotFound">Das Profil, das in dieser Regel referenziert wird, existiert scheinbar nicht mehr. Das alphabetisch erste wurde stattdessen ausgewählt.</string>
|
||||||
|
<string name="closeNotifications">Benachrichtigung(en) schließen</string>
|
||||||
|
<string name="comparisonCaseInsensitive">Groß-/Kleinschreibung ist egal.</string>
|
||||||
|
<string name="notificationCloseActionExplanation">Wenn Sie keine Kriterien angeben, werden ALLE Benachrichtigungen geschlossen. Es wird also empfohlen, zumindest eine Anwendung zu spezifizieren und/oder Titel oder Text anzugeben.</string>
|
||||||
</resources>
|
</resources>
|
@ -663,4 +663,7 @@
|
|||||||
<string name="enterTitle">Inserte un título.</string>
|
<string name="enterTitle">Inserte un título.</string>
|
||||||
<string name="enterText">Inserte un texto.</string>
|
<string name="enterText">Inserte un texto.</string>
|
||||||
<string name="profileWasNotFound">El perfil utilizado en esta regla ya no parece existir. Se ha seleccionado el primero alfabéticamente.</string>
|
<string name="profileWasNotFound">El perfil utilizado en esta regla ya no parece existir. Se ha seleccionado el primero alfabéticamente.</string>
|
||||||
|
<string name="notificationCloseActionExplanation">Si no especifica ningún criterio, esta acción cerrará TODAS las notificaciones. Por lo tanto, se recomienda al menos especificar criterios para al menos 1 de la aplicación, título o texto.</string>
|
||||||
|
<string name="closeNotifications">Cerrar notificación(es)</string>
|
||||||
|
<string name="comparisonCaseInsensitive">Las comparaciones se realizan sin distinción de mayúsculas y minúsculas</string>
|
||||||
</resources>
|
</resources>
|
@ -664,4 +664,7 @@
|
|||||||
<string name="enterText">Immettere un testo.</string>
|
<string name="enterText">Immettere un testo.</string>
|
||||||
<string name="info">Info</string>
|
<string name="info">Info</string>
|
||||||
<string name="profileWasNotFound">Il profilo utilizzato in questa regola non sembra più esistere. Il primo in ordine alfabetico è stato selezionato.</string>
|
<string name="profileWasNotFound">Il profilo utilizzato in questa regola non sembra più esistere. Il primo in ordine alfabetico è stato selezionato.</string>
|
||||||
|
<string name="comparisonCaseInsensitive">I confronti sono fatti caso-INsensitive</string>
|
||||||
|
<string name="closeNotifications">Chiudi notifica(e)</string>
|
||||||
|
<string name="notificationCloseActionExplanation">Se non specifichi alcun criterio, questa azione chiuderà TUTTE le notifiche. Quindi si consiglia di specificare almeno i criteri per almeno 1 di applicazione, titolo o testo.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -662,4 +662,7 @@
|
|||||||
<string name="enterText">Voer een tekst in.</string>
|
<string name="enterText">Voer een tekst in.</string>
|
||||||
<string name="enterTitle">Voer een titel in.</string>
|
<string name="enterTitle">Voer een titel in.</string>
|
||||||
<string name="createNotification">Melding maken</string>
|
<string name="createNotification">Melding maken</string>
|
||||||
|
<string name="notificationCloseActionExplanation">Als u geen criteria opgeeft, worden met deze actie ALLE meldingen gesloten. Het is dus aan te raden om in ieder geval criteria te specificeren voor minimaal 1 van de toepassing, titel of tekst.</string>
|
||||||
|
<string name="closeNotifications">Melding(en) sluiten</string>
|
||||||
|
<string name="comparisonCaseInsensitive">Vergelijkingen worden gedaan case-INsensitief</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -760,6 +760,7 @@
|
|||||||
<string name="enterText">Enter a text.</string>
|
<string name="enterText">Enter a text.</string>
|
||||||
<string name="info">Info</string>
|
<string name="info">Info</string>
|
||||||
<string name="profileWasNotFound">The profile used in this rule doesn\'t seem to exist anymore. The alphabetically first one has been selected.</string>
|
<string name="profileWasNotFound">The profile used in this rule doesn\'t seem to exist anymore. The alphabetically first one has been selected.</string>
|
||||||
<string name="notificationCloseActionExplanation">If you don\'t specify any criteria this action will close ALL applicable notifications. So it\'s advised to at least specify criteria for at least 1 of application, title or text.</string>
|
<string name="notificationCloseActionExplanation">If you don\'t specify any criteria this action will close ALL notifications. So it\'s advised to at least specify criteria for at least 1 of application, title or text.</string>
|
||||||
<string name="closeNotifications">Close notification(s)</string>
|
<string name="closeNotifications">Close notification(s)</string>
|
||||||
|
<string name="comparisonCaseInsensitive">Comparisons are done case-INsensitive</string>
|
||||||
</resources>
|
</resources>
|
@ -1,2 +1,3 @@
|
|||||||
* New action: Create notification
|
* New action: Create notification
|
||||||
|
* New action: Close notification(s)
|
||||||
* Fixed: Translation bug in dutch variables text
|
* Fixed: Translation bug in dutch variables text
|
Loading…
Reference in New Issue
Block a user