I am not getting consistent results doing a fairly simple task: turning NFC on or off.
I am using Oxygen 9.0.13 (Android Pie).
My flow consists of two actions: Start Activity and ControlUI.
Start Activity
Action (android.intent.category.VIEW)
Category List (android.intent.category.DEFAULT)
Package Name (com.android.settings)
Class Name (com.andriod.settings.Settings$Advance
Flag List
FLAG_ACTIVITY_NEW_TASK
FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
The second Action is ControlUI. Here is the script to Turn NFC ON:
sle=1000;
sleep(sle);
text = getText(984, 572);
sleep(sle);
control_is_off=text=="OFF";
if (control_is_off)
click("OFF");
sleep(sle); back(); back();
The irritating thing about my flow is that works sometimes and other times not. It just is not consistent. Anyone have a suggestion or two? Thanks.
Inconsistent outcomes with script
Moderator: Martin
Re: Inconsistent outcomes with script
The class name is spelled wrong but that's probably just a typo from when you wrote the post. The correct one for me is: com.android.settings.Settings$AdvancedConnectedDeviceActivity
Your script worked fine for me when I inputted my co-ordinates, but as a general rule, I try not to use co-ordinates as it varies depending on device and perhaps DPI setting as well. Maybe you can give the script below a try after double-checking the co-ordinates:
You can also just use the NFC Enabled condition, and if it's equal to false, use the same Start Activity and Control UI script but without the if statement.
Your script worked fine for me when I inputted my co-ordinates, but as a general rule, I try not to use co-ordinates as it varies depending on device and perhaps DPI setting as well. Maybe you can give the script below a try after double-checking the co-ordinates:
Code: Select all
sleep(500);
if (getText(x, y) == "OFF")
{
click("NFC");
}
sleep(500);
back();
back();
Last edited by Pepy on 31 May 2019 01:45, edited 1 time in total.
Hope my post was helpful
Device: OnePlus 5T running crDroid, rooted with Magisk
Device: OnePlus 5T running crDroid, rooted with Magisk
Re: Inconsistent outcomes with script
Thanks for the response and the much cleaner code.
Yes, I truncated the class name. Sorry about that. That was all I could see on the screen.
I have found two other ways to accomplish the NFC task, both of which seem to work better for me.
1. Instead of using Start Activity, I used Launch App. The same Package Name and Class name were used; it seems to work better than Start Activity. I don't understand why, but that is what I experienced.
2. Using quickSettings() for NFC seemed to work reasonably well. Now that the Info, Gesture, and Close buttons are drag-able on the Overlay control of Control UI, that seemed to work pretty well too.
Your idea of using the NFC Enabled condition could easily be used with either of the above to simply matters. Just a click on the NFC tile in quickSettings() can toggle NFC the way I need.
thanks again.
Yes, I truncated the class name. Sorry about that. That was all I could see on the screen.
I have found two other ways to accomplish the NFC task, both of which seem to work better for me.
1. Instead of using Start Activity, I used Launch App. The same Package Name and Class name were used; it seems to work better than Start Activity. I don't understand why, but that is what I experienced.
2. Using quickSettings() for NFC seemed to work reasonably well. Now that the Info, Gesture, and Close buttons are drag-able on the Overlay control of Control UI, that seemed to work pretty well too.
Your idea of using the NFC Enabled condition could easily be used with either of the above to simply matters. Just a click on the NFC tile in quickSettings() can toggle NFC the way I need.
thanks again.
Re: Inconsistent outcomes with script
Start Activity just seems like a more advanced version of Launch App, so I'm not sure why it doesn't work as well.
Following up with my idea, if you're going to be using Launch App, this flow should be enough to get the job done: http://automagic4android.com/flow.php?i ... 38fd2b0d83
I personally would prefer using the first method since I won't need to worry about the flow breaking if I ever remove or movd the tile to another page.
Following up with my idea, if you're going to be using Launch App, this flow should be enough to get the job done: http://automagic4android.com/flow.php?i ... 38fd2b0d83
I personally would prefer using the first method since I won't need to worry about the flow breaking if I ever remove or movd the tile to another page.
Last edited by Pepy on 01 Jun 2019 23:21, edited 1 time in total.
Hope my post was helpful
Device: OnePlus 5T running crDroid, rooted with Magisk
Device: OnePlus 5T running crDroid, rooted with Magisk
Re: Inconsistent outcomes with script
Need to debug what is the error per execution. Put debug dialog after the control UI. You can see the value of the {text} and {control_is_off}. Most likely it is null or some other data. Control UI silent error usually caused by insufficient sleep. Most of the time, it is the first sleep from previous action. So the start activity might have signaled Automagic to continue to next action, Control UI. But the UI of the setting hasn't fully loaded yet, causing null data in {text} when retrieved, inconsistent outcome. Sometimes it loaded up fast, hence the action is successful.
As Pepy pointed out, just use Launch App for most cases, usually it loads up faster. Use Start Activity only when the activity require extra fields, or need some form of data field or special flags ("exclude from recents" might be needed for password/security related task).
As Pepy pointed out, just use Launch App for most cases, usually it loads up faster. Use Start Activity only when the activity require extra fields, or need some form of data field or special flags ("exclude from recents" might be needed for password/security related task).
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.