diff --git a/app/src/main/java/com/jens/automation2/Actions.java b/app/src/main/java/com/jens/automation2/Actions.java index 2317c7d..7fd67c7 100644 --- a/app/src/main/java/com/jens/automation2/Actions.java +++ b/app/src/main/java/com/jens/automation2/Actions.java @@ -1047,7 +1047,7 @@ public class Actions try { - Intent externalActivityIntent; + Intent externalApplicationIntent; if (!startByAction) { @@ -1060,15 +1060,13 @@ public class Actions Miscellaneous.logEvent("i", "StartOtherApp", "Starting app by activity: " + packageName + " " + className, 3); - externalActivityIntent = new Intent(Intent.ACTION_MAIN); - externalActivityIntent.addCategory(Intent.CATEGORY_LAUNCHER); + externalApplicationIntent = new Intent(Intent.ACTION_MAIN); + externalApplicationIntent.addCategory(Intent.CATEGORY_LAUNCHER); -// if(packageName.equals("dummyPkg")) -// externalActivityIntent.setAction(className); -// else - externalActivityIntent.setClassName(packageName, className); + if(packageName.equals("dummyPkg")) + externalApplicationIntent.setAction(className); - if (!Miscellaneous.doesActivityExist(externalActivityIntent, Miscellaneous.getAnyContext())) + if (!Miscellaneous.doesActivityExist(externalApplicationIntent, Miscellaneous.getAnyContext())) Miscellaneous.logEvent("w", "StartOtherApp", "Activity not found: " + className, 2); } else @@ -1076,34 +1074,32 @@ public class Actions // selected by action Miscellaneous.logEvent("i", "StartOtherApp", "Starting app by action: " + param, 3); - externalActivityIntent = new Intent(); + externalApplicationIntent = new Intent(); if (!params[0].equals(dummyPackageString)) - externalActivityIntent.setPackage(params[0]); + externalApplicationIntent.setPackage(params[0]); - externalActivityIntent.setPackage("net.christianbeier.droidvnc_ng"); + externalApplicationIntent.setAction(params[1]); - if (params[2].equals(ActivityManageActionStartActivity.startByServiceString)) + if (params[2].equals(ActivityManageActionStartActivity.startByServiceString) || params[2].equals(ActivityManageActionStartActivity.startByForegroundServiceString)) { - //externalActivityIntent.setComponent(new ComponentName(params[0], params[1])); - externalActivityIntent.setComponent(new ComponentName("net.christianbeier.droidvnc_ng", ".MainService")); + externalApplicationIntent.setComponent(new ComponentName(params[0], params[2])); } - - externalActivityIntent.setAction(params[1]); } - externalActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + externalApplicationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Pack intents - externalActivityIntent = packParametersIntoIntent(externalActivityIntent, params, 3); + externalApplicationIntent = packParametersIntoIntent(externalApplicationIntent, params, 3); if (params[2].equals(ActivityManageActionStartActivity.startByActivityString)) - automationServerRef.startActivity(externalActivityIntent); - if (params[2].equals(ActivityManageActionStartActivity.startByServiceString)) - //automationServerRef.startService(externalActivityIntent); - automationServerRef.startForegroundService(externalActivityIntent); + automationServerRef.startActivity(externalApplicationIntent); + else if (params[2].equals(ActivityManageActionStartActivity.startByServiceString)) + automationServerRef.startService(externalApplicationIntent); + else if (params[2].equals(ActivityManageActionStartActivity.startByForegroundServiceString)) + automationServerRef.startForegroundService(externalApplicationIntent); else - automationServerRef.sendBroadcast(externalActivityIntent); + automationServerRef.sendBroadcast(externalApplicationIntent); } catch (Exception e) { diff --git a/app/src/main/java/com/jens/automation2/ActivityManageActionStartActivity.java b/app/src/main/java/com/jens/automation2/ActivityManageActionStartActivity.java index eb4b670..03eb63d 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageActionStartActivity.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageActionStartActivity.java @@ -48,17 +48,18 @@ public class ActivityManageActionStartActivity extends Activity */ ListView lvIntentPairs; - EditText etParameterName, etParameterValue, etPackageName, etActivityOrActionPath; + EditText etParameterName, etParameterValue, etPackageName, etActivityOrActionPath, etClassName; Button bSelectApp, bAddIntentPair, bSaveActionStartOtherActivity, showStartProgramExamples; Spinner spinnerParameterType; boolean edit = false; ProgressDialog progressDialog = null; - RadioButton rbStartAppSelectByActivity, rbStartAppSelectByAction, rbStartAppByActivity, rbStartAppByBroadcast, rbStartAppByService; + RadioButton rbStartAppSelectByActivity, rbStartAppSelectByAction, rbStartAppByActivity, rbStartAppByBroadcast, rbStartAppByService, rbStartAppByForegroundService; final String urlShowExamples = "https://server47.de/automation/examples_startProgram.html"; final static String startByActivityString = "0"; final static String startByBroadcastString = "1"; final static String startByServiceString = "2"; + final static String startByForegroundServiceString = "3"; final static int requestCodeForRequestQueryAllPackagesPermission = 4711; @@ -72,6 +73,7 @@ public class ActivityManageActionStartActivity extends Activity lvIntentPairs = (ListView)findViewById(R.id.lvIntentPairs); etParameterName = (EditText)findViewById(R.id.etParameterName); etParameterValue = (EditText)findViewById(R.id.etParameterValue); + etClassName = (EditText)findViewById(R.id.etClassName); bSelectApp = (Button)findViewById(R.id.bSelectApp); bAddIntentPair = (Button)findViewById(R.id.bAddIntentPair); bSaveActionStartOtherActivity = (Button)findViewById(R.id.bSaveActionStartOtherActivity); @@ -84,6 +86,7 @@ public class ActivityManageActionStartActivity extends Activity rbStartAppByActivity = (RadioButton)findViewById(R.id.rbStartAppByActivity); rbStartAppByBroadcast = (RadioButton)findViewById(R.id.rbStartAppByBroadcast); rbStartAppByService = (RadioButton)findViewById(R.id.rbStartAppByService); + rbStartAppByForegroundService = (RadioButton)findViewById(R.id.rbStartAppByForegroundService); intentTypeSpinnerAdapter = new ArrayAdapter(this, R.layout.text_view_for_poi_listview_mediumtextsize, ActivityManageActionStartActivity.supportedIntentTypes); spinnerParameterType.setAdapter(intentTypeSpinnerAdapter); @@ -227,17 +230,23 @@ public class ActivityManageActionStartActivity extends Activity if (rbStartAppSelectByActivity.isChecked()) parameter2 += etPackageName.getText().toString() + ";" + etActivityOrActionPath.getText().toString(); - else { + else + { if (etPackageName.getText().toString() != null && etPackageName.getText().toString().length() > 0) parameter2 += etPackageName.getText().toString() + ";" + etActivityOrActionPath.getText().toString(); else parameter2 += Actions.dummyPackageString + ";" + etActivityOrActionPath.getText().toString(); + +// if(etClassName.getText().toString().length() > 0) + parameter2 += ";" + etClassName.getText().toString(); } if (rbStartAppByActivity.isChecked()) parameter2 += ";" + startByActivityString; else if(rbStartAppByService.isChecked()) parameter2 += ";" + startByServiceString; + else if(rbStartAppByForegroundService.isChecked()) + parameter2 += ";" + startByForegroundServiceString; else parameter2 += ";" + startByBroadcastString; @@ -597,9 +606,19 @@ public class ActivityManageActionStartActivity extends Activity String[] params = input.getStringExtra(ActivityManageRule.intentNameActionParameter2).split(";"); - rbStartAppByActivity.setChecked(params[2].equals(startByActivityString)); - rbStartAppByBroadcast.setChecked(params[2].equals(startByBroadcastString)); - rbStartAppByService.setChecked(params[2].equals(startByServiceString)); + if(Miscellaneous.isNumeric(params[2])) // old configuration file + { + rbStartAppByActivity.setChecked(params[2].equals(startByActivityString)); + rbStartAppByBroadcast.setChecked(params[2].equals(startByBroadcastString)); + rbStartAppByService.setChecked(params[2].equals(startByServiceString)); + } + else + { + rbStartAppByActivity.setChecked(params[3].equals(startByActivityString)); + rbStartAppByBroadcast.setChecked(params[3].equals(startByBroadcastString)); + rbStartAppByService.setChecked(params[3].equals(startByServiceString)); + rbStartAppByForegroundService.setChecked(params[3].equals(startByForegroundServiceString)); + } int startIndex = -1; @@ -614,10 +633,11 @@ public class ActivityManageActionStartActivity extends Activity etPackageName.setText(params[0]); etActivityOrActionPath.setText(params[1]); + etClassName.setText(params[2]); } - if (params.length >= 3) - startIndex = 3; + if (params.length >= 4) + startIndex = 4; if(startIndex > -1 && params.length > startIndex) { diff --git a/app/src/main/java/com/jens/automation2/ReceiverCoordinator.java b/app/src/main/java/com/jens/automation2/ReceiverCoordinator.java index 3dbc83d..8af7586 100644 --- a/app/src/main/java/com/jens/automation2/ReceiverCoordinator.java +++ b/app/src/main/java/com/jens/automation2/ReceiverCoordinator.java @@ -391,7 +391,7 @@ public class ReceiverCoordinator } } - if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.headsetPlugged)) + if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.headsetPlugged)) { if(!HeadphoneJackListener.isHeadphoneJackListenerActive()) { diff --git a/app/src/main/res/layout/activity_manage_action_start_activity.xml b/app/src/main/res/layout/activity_manage_action_start_activity.xml index b5faf5b..e1cff03 100644 --- a/app/src/main/res/layout/activity_manage_action_start_activity.xml +++ b/app/src/main/res/layout/activity_manage_action_start_activity.xml @@ -135,6 +135,12 @@ android:layout_height="wrap_content" android:text="@string/startAppByStartService" /> + + @@ -187,6 +193,25 @@ + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 848c591..b7c6c42 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -887,4 +887,6 @@ Variables are only available for parameter types String and URI If you want to specify a parameter you also have to click \"Add intent pair\". Otherwise your changes will not be saved. This trigger will be valid if you just disconnected from the wifi specified above OR while the service is still starting and if you\'re not connected to any wifi. If you want the trigger to fire only when you\'re explicitly disconnecting from a certain wifi, add another trigger \"service is not starting\". + Class full name + by startForegroundService() \ No newline at end of file