From d63841dd2735188c7b61e045910797b9fc0d3441 Mon Sep 17 00:00:00 2001 From: Jens Date: Wed, 25 Feb 2026 23:01:45 +0100 Subject: [PATCH] Further actions for trigger url action --- .../java/com/jens/automation2/Action.java | 6 +- .../automation2/ActivityMainTabLayout.java | 11 ++-- .../ActivityManageActionTriggerUrl.java | 5 ++ .../com/jens/automation2/Miscellaneous.java | 57 +++++++++++++++---- .../jens/automation2/XmlFileInterface.java | 4 +- .../automation2/receivers/NfcReceiver.java | 2 +- .../activity_manage_action_trigger_url.xml | 11 ++++ app/src/main/res/values/strings.xml | 1 + .../metadata/android/en-US/changelogs/147.txt | 1 + .../android/en-US/full_description.txt | 4 +- 10 files changed, 79 insertions(+), 23 deletions(-) create mode 100644 fastlane/metadata/android/en-US/changelogs/147.txt diff --git a/app/src/main/java/com/jens/automation2/Action.java b/app/src/main/java/com/jens/automation2/Action.java index 9b3442c..433e50f 100644 --- a/app/src/main/java/com/jens/automation2/Action.java +++ b/app/src/main/java/com/jens/automation2/Action.java @@ -8,6 +8,7 @@ import android.widget.Toast; import org.apache.commons.lang3.StringUtils; +import java.net.URLEncoder; import java.util.ArrayList; import java.util.HashMap; import java.util.Locale; @@ -689,8 +690,8 @@ public class Action try { url = Miscellaneous.replaceVariablesInText(url, context); - if(!StringUtils.isEmpty(params)) - params = Miscellaneous.replaceVariablesInText(params, context); +// if(!StringUtils.isEmpty(params)) +// params = URLEncoder.encode(Miscellaneous.replaceVariablesInText(params, context), "UTF-8"); Actions myAction = new Actions(); @@ -745,7 +746,6 @@ public class Action httpParams.put(pieces[0], pieces[1]); } } - } String response = httpErrorDefaultText; diff --git a/app/src/main/java/com/jens/automation2/ActivityMainTabLayout.java b/app/src/main/java/com/jens/automation2/ActivityMainTabLayout.java index e3f1baa..2d290b4 100644 --- a/app/src/main/java/com/jens/automation2/ActivityMainTabLayout.java +++ b/app/src/main/java/com/jens/automation2/ActivityMainTabLayout.java @@ -5,6 +5,7 @@ import android.app.TabActivity; import android.content.Intent; import android.content.res.Configuration; import android.content.res.Resources; +import android.nfc.NfcAdapter; import android.os.Bundle; import android.util.DisplayMetrics; import android.widget.TabHost; @@ -61,22 +62,24 @@ public class ActivityMainTabLayout extends TabActivity tabHost.setCurrentTab(Settings.startScreen); } - @Override protected void onResume() { super.onResume(); Miscellaneous.setDisplayLanguage(this); // Miscellaneous.logEvent("i", "NFC", "ActivityMainTabLayout.onResume().", 5); - NfcReceiver.checkIntentForNFC(this, getIntent()); -// NfcReceiver.checkIntentForNFC(this, new Intent(this.getApplicationContext(), this.getClass())); + if(!(getIntent().getAction().isEmpty()) && getIntent().getAction().equals(NfcAdapter.ACTION_NDEF_DISCOVERED)) + { + NfcReceiver.checkIntentForNFC(this, getIntent()); + moveTaskToBack(true); + } } @Override protected void onNewIntent(Intent intent) { // Miscellaneous.logEvent("i", "NFC", "ActivityMainTabLayout.onNewIntent().", 5); -// setIntent(intent); + NfcReceiver.checkIntentForNFC(this, intent); } } \ No newline at end of file diff --git a/app/src/main/java/com/jens/automation2/ActivityManageActionTriggerUrl.java b/app/src/main/java/com/jens/automation2/ActivityManageActionTriggerUrl.java index 728c399..8922205 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageActionTriggerUrl.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageActionTriggerUrl.java @@ -19,6 +19,7 @@ import android.widget.EditText; import android.widget.ListView; import android.widget.RadioButton; import android.widget.TableLayout; +import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; @@ -38,6 +39,7 @@ public class ActivityManageActionTriggerUrl extends Activity CheckBox chkTriggerUrlUseAuthentication; RadioButton rbTriggerUrlMethodGet, rbTriggerUrlMethodPost; TableLayout tlTriggerUrlAuthentication; + TextView tvHttpParameterExplanation; ArrayAdapter httpParametersAdapter; private ArrayList httpParamsList = new ArrayList<>(); @@ -67,6 +69,7 @@ public class ActivityManageActionTriggerUrl extends Activity etParameterName = (EditText) findViewById(R.id.etParameterName); etParameterValue = (EditText)findViewById(R.id.etParameterValue); bAddHttpParam = (Button)findViewById(R.id.bAddHttpParam); + tvHttpParameterExplanation = (TextView)findViewById(R.id.tvHttpParameterExplanation); etParameterName.setEnabled(false); etParameterValue.setEnabled(false); @@ -85,6 +88,8 @@ public class ActivityManageActionTriggerUrl extends Activity } }); + tvHttpParameterExplanation.setText(String.format(getResources().getString(R.string.httpParametersExplanation), Miscellaneous.httpMainData, Miscellaneous.doNoEncodingString)); + httpParametersAdapter = new ArrayAdapter(this, R.layout.text_view_for_poi_listview_mediumtextsize, httpParamsList); bSaveTriggerUrl.setOnClickListener(new OnClickListener() diff --git a/app/src/main/java/com/jens/automation2/Miscellaneous.java b/app/src/main/java/com/jens/automation2/Miscellaneous.java index 7e4de85..2f3ddc1 100644 --- a/app/src/main/java/com/jens/automation2/Miscellaneous.java +++ b/app/src/main/java/com/jens/automation2/Miscellaneous.java @@ -128,10 +128,13 @@ public class Miscellaneous extends Service protected static String writeableFolderStringCache = null; protected final static String http_error_string = "HTTP_ERROR"; protected final static String last_trigger_url_result_string = "last_trigger_url_result"; + protected final static String httpMainData = "httpMainData"; + protected final static String doNoEncodingString = "NoEncoding"; + protected final static String httpEncoding = "UTF-8"; public static Context startupContext; public static final String lineSeparator = System.getProperty("line.separator"); - + public static String downloadURL(String url, String username, String password, String method, Map httpParams) { HttpClient httpclient = new DefaultHttpClient(); @@ -166,6 +169,7 @@ public class Miscellaneous extends Service if(httpParams.size() > 0) { connection.setRequestMethod("POST"); + connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setDoInput(true); connection.setDoOutput(true); @@ -175,8 +179,8 @@ public class Miscellaneous extends Service paramPairs.add(new BasicNameValuePair(key, httpParams.get(key))); OutputStream os = connection.getOutputStream(); - BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); - writer.write(getQuery(paramPairs)); + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, httpEncoding)); + writer.write(getQuery(paramPairs, method)); writer.flush(); writer.close(); } @@ -206,21 +210,52 @@ public class Miscellaneous extends Service } } - private static String getQuery(List params) throws UnsupportedEncodingException + private static String getQuery(List params, String method) throws UnsupportedEncodingException { StringBuilder result = new StringBuilder(); + boolean first = true; for (NameValuePair pair : params) { - if (first) - first = false; - else - result.append("&"); + if (method.equals(ActivityManageActionTriggerUrl.methodGet)) + { + if (first) + first = false; + else + result.append("&"); + } + else if (pair.getName().startsWith(httpMainData)) + continue; // if post and main data skip lookup run + + result.append(pair.getName()); - result.append(URLEncoder.encode(pair.getName(), "UTF-8")); result.append("="); - result.append(URLEncoder.encode(pair.getValue(), "UTF-8")); + + if (pair.getName().endsWith(doNoEncodingString)) + result.append(URLEncoder.encode(pair.getValue(), httpEncoding)); + else + result.append(pair.getValue()); + } + + /* + If method is POST and there's a httpMainData field, we transfer + this one at the end without parameter name and equals sign. + */ + if (method.equals(ActivityManageActionTriggerUrl.methodPost)) + { + for (NameValuePair pair : params) + { + if (pair.getName().startsWith(httpMainData)) + { + if (pair.getName().endsWith(doNoEncodingString)) + result.append(pair.getValue()); + else + result.append(URLEncoder.encode(pair.getValue(), httpEncoding)); + + return result.toString(); + } + } } return result.toString(); @@ -819,7 +854,7 @@ public class Miscellaneous extends Service String notificationTitle = NotificationListener.getLastNotification().getTitle(); if (notificationTitle != null && notificationTitle.length() > 0) - source = source.replace("[notificationTitle]", escapeStringForUrl(notificationTitle)); + source = source.replace("[notificationTitle]", notificationTitle); else { source = source.replace("[notificationTitle]", "notificationTitle unknown"); diff --git a/app/src/main/java/com/jens/automation2/XmlFileInterface.java b/app/src/main/java/com/jens/automation2/XmlFileInterface.java index b42cc97..e791f5f 100644 --- a/app/src/main/java/com/jens/automation2/XmlFileInterface.java +++ b/app/src/main/java/com/jens/automation2/XmlFileInterface.java @@ -711,7 +711,7 @@ public class XmlFileInterface private static Rule readRule(XmlPullParser parser) throws XmlPullParserException, IOException { - /* FILE EXAMPE: + /* FILE EXAMPLE: * ***************** * * @@ -1095,7 +1095,7 @@ public class XmlFileInterface private static Action readAction(XmlPullParser parser) throws IOException, XmlPullParserException { - /* FILE EXAMPE: + /* FILE EXAMPLE: * ***************** * * diff --git a/app/src/main/java/com/jens/automation2/receivers/NfcReceiver.java b/app/src/main/java/com/jens/automation2/receivers/NfcReceiver.java index b146937..7671b76 100644 --- a/app/src/main/java/com/jens/automation2/receivers/NfcReceiver.java +++ b/app/src/main/java/com/jens/automation2/receivers/NfcReceiver.java @@ -63,7 +63,7 @@ public class NfcReceiver { Miscellaneous.logEvent("i", "NFC", "ACTION_NDEF_DISCOVERED", 4); - getNfcAdapter(context); + getNfcAdapter(context); if(nfcAdapter == null) // if it's still null the device doesn't support NFC { diff --git a/app/src/main/res/layout/activity_manage_action_trigger_url.xml b/app/src/main/res/layout/activity_manage_action_trigger_url.xml index 4ac07a1..3280b32 100644 --- a/app/src/main/res/layout/activity_manage_action_trigger_url.xml +++ b/app/src/main/res/layout/activity_manage_action_trigger_url.xml @@ -140,6 +140,17 @@ + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9f45096..7c7f6b0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -977,4 +977,5 @@ Enter a value. Set system setting I do not keep a list of possible settings. Please find those settings on your own. See here for some (incomplete) examples. + If any parameter name starts with %1$s while method is POST, it will not be transmitted like the other parameters (with key=value), but transferred as main data.\nIf the parameter ends with %2$s, no encoding will be performed. \ No newline at end of file diff --git a/fastlane/metadata/android/en-US/changelogs/147.txt b/fastlane/metadata/android/en-US/changelogs/147.txt new file mode 100644 index 0000000..68e038d --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/147.txt @@ -0,0 +1 @@ +* Added: Added further options to the trigger url action. \ No newline at end of file diff --git a/fastlane/metadata/android/en-US/full_description.txt b/fastlane/metadata/android/en-US/full_description.txt index 3d0ff17..31c6fd7 100644 --- a/fastlane/metadata/android/en-US/full_description.txt +++ b/fastlane/metadata/android/en-US/full_description.txt @@ -64,8 +64,8 @@ Supported actions: * Change location setting * Send text message -It's quite hard to keep this app working across the many different hardwares as well as the many changes Android undergoes over the versions. I can test it in the emulator, but that cannot show all bugs. -So if a certain feature is not working on your device - let me know. Over the years I have fixed almost all bugs that have been reasonably reported to me. But for that I'm dependend on your input. +It's quite hard to keep this app working across the many different devices as well as the many changes Android undergoes over the versions. I can test it in the emulator, but that cannot show all bugs. +So if a certain feature is not working on your device - let me know. Over the years I have fixed almost all bugs that have been reasonably reported to me. But for that I'm dependent on your input. If you have a problem and think about contacting me please - update to the latest version first and see if your problem persists there, too.