send broadcast with intents

This commit is contained in:
jens 2022-06-07 17:18:35 +02:00
parent 2361c758c9
commit 5272b56032
2 changed files with 94 additions and 85 deletions

View File

@ -368,6 +368,10 @@ public class Action
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.unknown)); returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.unknown));
} }
} }
else if(this.getAction().equals(Action_Enum.sendBroadcast))
{
returnString.append(": " + parameter2.replace(Action.actionParameter2Split, "; ").replace(Action.intentPairSeparator, "/"));
}
else if (parameter2 != null && parameter2.length() > 0) else if (parameter2 != null && parameter2.length() > 0)
returnString.append(": " + parameter2.replace(Action.actionParameter2Split, "; ")); returnString.append(": " + parameter2.replace(Action.actionParameter2Split, "; "));
} }

View File

@ -202,7 +202,9 @@ public class Actions
{ {
String[] parts = action.split(Action.actionParameter2Split); String[] parts = action.split(Action.actionParameter2Split);
broadcastIntent.setAction(parts[0]); broadcastIntent.setAction(parts[0]);
add params
String[] intentparts = parts[1].split(";");
broadcastIntent = packParametersIntoIntent(broadcastIntent, intentparts, 0);
} }
else else
broadcastIntent.setAction(action); broadcastIntent.setAction(action);
@ -1017,8 +1019,6 @@ public class Actions
{ {
Intent externalActivityIntent; Intent externalActivityIntent;
int paramsStartIndex;
if (!startByAction) if (!startByAction)
{ {
// selected by activity // selected by activity
@ -1030,8 +1030,6 @@ public class Actions
Miscellaneous.logEvent("i", "StartOtherApp", "Starting app by activity: " + packageName + " " + className, 3); Miscellaneous.logEvent("i", "StartOtherApp", "Starting app by activity: " + packageName + " " + className, 3);
paramsStartIndex = 2;
externalActivityIntent = new Intent(Intent.ACTION_MAIN); externalActivityIntent = new Intent(Intent.ACTION_MAIN);
externalActivityIntent.addCategory(Intent.CATEGORY_LAUNCHER); externalActivityIntent.addCategory(Intent.CATEGORY_LAUNCHER);
@ -1059,7 +1057,23 @@ public class Actions
externalActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); externalActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Pack intents // Pack intents
for (int i = 3; i < params.length; i++) externalActivityIntent = packParametersIntoIntent(externalActivityIntent, params, 3);
if (params[2].equals(ActivityManageActionStartActivity.startByActivityString))
automationServerRef.startActivity(externalActivityIntent);
else
automationServerRef.sendBroadcast(externalActivityIntent);
}
catch (Exception e)
{
Miscellaneous.logEvent("e", "StartOtherApp", automationServerRef.getResources().getString(R.string.errorStartingOtherActivity) + ": " + Log.getStackTraceString(e), 2);
Toast.makeText(automationServerRef, automationServerRef.getResources().getString(R.string.errorStartingOtherActivity) + ": " + e.getMessage(), Toast.LENGTH_LONG).show();
}
}
public static Intent packParametersIntoIntent(Intent intent, String[] params, int startIndex)
{
for (int i = startIndex; i < params.length; i++)
{ {
String[] singleParam = params[i].split(Action.intentPairSeparator); String[] singleParam = params[i].split(Action.intentPairSeparator);
@ -1076,80 +1090,71 @@ public class Actions
if (singleParam[0].equals("boolean")) if (singleParam[0].equals("boolean"))
{ {
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
externalActivityIntent.putExtra(singleParam[1], Boolean.parseBoolean(singleParam[2])); intent.putExtra(singleParam[1], Boolean.parseBoolean(singleParam[2]));
} }
else if (singleParam[0].equals("byte")) else if (singleParam[0].equals("byte"))
{ {
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
externalActivityIntent.putExtra(singleParam[1], Byte.parseByte(singleParam[2])); intent.putExtra(singleParam[1], Byte.parseByte(singleParam[2]));
} }
else if (singleParam[0].equals("char")) else if (singleParam[0].equals("char"))
{ {
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
externalActivityIntent.putExtra(singleParam[1], singleParam[2].charAt(0)); intent.putExtra(singleParam[1], singleParam[2].charAt(0));
} }
else if (singleParam[0].equals("CharSequence")) else if (singleParam[0].equals("CharSequence"))
{ {
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
externalActivityIntent.putExtra(singleParam[1], (CharSequence) singleParam[2]); intent.putExtra(singleParam[1], (CharSequence) singleParam[2]);
} }
else if (singleParam[0].equals("double")) else if (singleParam[0].equals("double"))
{ {
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
externalActivityIntent.putExtra(singleParam[1], Double.parseDouble(singleParam[2])); intent.putExtra(singleParam[1], Double.parseDouble(singleParam[2]));
} }
else if (singleParam[0].equals("float")) else if (singleParam[0].equals("float"))
{ {
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
externalActivityIntent.putExtra(singleParam[1], Float.parseFloat(singleParam[2])); intent.putExtra(singleParam[1], Float.parseFloat(singleParam[2]));
} }
else if (singleParam[0].equals("int")) else if (singleParam[0].equals("int"))
{ {
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
externalActivityIntent.putExtra(singleParam[1], Integer.parseInt(singleParam[2])); intent.putExtra(singleParam[1], Integer.parseInt(singleParam[2]));
} }
else if (singleParam[0].equals("long")) else if (singleParam[0].equals("long"))
{ {
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
externalActivityIntent.putExtra(singleParam[1], Long.parseLong(singleParam[2])); intent.putExtra(singleParam[1], Long.parseLong(singleParam[2]));
} }
else if (singleParam[0].equals("short")) else if (singleParam[0].equals("short"))
{ {
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
externalActivityIntent.putExtra(singleParam[1], Short.parseShort(singleParam[2])); intent.putExtra(singleParam[1], Short.parseShort(singleParam[2]));
} }
else if (singleParam[0].equals("Uri")) else if (singleParam[0].equals("Uri"))
{ {
if (singleParam[1].equalsIgnoreCase("IntentData")) if (singleParam[1].equalsIgnoreCase("IntentData"))
{ {
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with value " + singleParam[2] + " as standard data parameter.", 3); Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with value " + singleParam[2] + " as standard data parameter.", 3);
externalActivityIntent.setData(Uri.parse(singleParam[2])); intent.setData(Uri.parse(singleParam[2]));
} }
else else
{ {
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
externalActivityIntent.putExtra(singleParam[1], Uri.parse(singleParam[2])); intent.putExtra(singleParam[1], Uri.parse(singleParam[2]));
} }
} }
else if (singleParam[0].equals("String")) else if (singleParam[0].equals("String"))
{ {
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3); Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
externalActivityIntent.putExtra(singleParam[1], singleParam[2]); intent.putExtra(singleParam[1], singleParam[2]);
} }
else else
Miscellaneous.logEvent("w", "StartOtherApp", "Unknown type of parameter " + singleParam[0] + " found. Name " + singleParam[1] + " and value " + singleParam[2], 3); Miscellaneous.logEvent("w", "StartOtherApp", "Unknown type of parameter " + singleParam[0] + " found. Name " + singleParam[1] + " and value " + singleParam[2], 3);
} }
if (params[2].equals(ActivityManageActionStartActivity.startByActivityString)) return intent;
automationServerRef.startActivity(externalActivityIntent);
else
automationServerRef.sendBroadcast(externalActivityIntent);
}
catch (Exception e)
{
Miscellaneous.logEvent("e", "StartOtherApp", automationServerRef.getResources().getString(R.string.errorStartingOtherActivity) + ": " + Log.getStackTraceString(e), 2);
Toast.makeText(automationServerRef, automationServerRef.getResources().getString(R.string.errorStartingOtherActivity) + ": " + e.getMessage(), Toast.LENGTH_LONG).show();
}
} }
public static void waitBeforeNextAction(Long waitTime) public static void waitBeforeNextAction(Long waitTime)