[solved] Widget to show and switch 2G/3G

General discussions about Automagic and automation in general

Moderator: Martin

Post Reply
User avatar
Rhonin
Posts: 19
Joined: 08 Apr 2015 05:23

[solved] Widget to show and switch 2G/3G

Post by Rhonin » 09 Aug 2017 07:50

Hi folx,

i tried yesterday to generate a widget to show the actual data connection - whether 2G LTE or 3G - Depending on that information i would like to switch the connection via the widget.

First problem is how to display the actual connection in the widget ? Do i have to generate a global_variable and if so how do i feed the variable with the neccessary information.
In a second step i would like to start a flow by clicking the widget - for example energy saving (Switch to 2G / switch GPS off .... and maybe some other parts....)
Someone knows if a MT-Tweak Profil can be accessed via Automagic ?

I haven't found a little example on how to succeed - only the time example

THX in advance for your help

Rhonin
Last edited by Rhonin on 09 Sep 2017 04:35, edited 1 time in total.
Automagic on rooted Xperia Z3c running on Android 5.1.1

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Widget to show and switch 2G/3G

Post by Desmanto » 09 Aug 2017 10:34

You should try out the tutorial for creating custom widget, it helps a lot to get a general idea how it works. https://automagic4android.com/en/help/c ... tom-widget

You need to create a global variable, example global_networkmode. Toggle the value between "Full network" and "Energy Saving".

Create a flow with no trigger, but enable the flow. Name : Network Toggle
1. Condition : Expression, global_networkmode == "Full network"
If yes, then you wanna toggle it to energy saving. Thus the action for true, will be turning off any network, GPS, or anything you want. While the false branch will do the reverse, turning on them back.

2. Action (true) : do whatever to turn off the GPS, bluetooth, wifi, set network mode to 2G or anything. You can add as many as action as needed. After finish, at the end of this true branch, put action Script : global_networkmode = "Energy Saving". To state that now the phone is in energy saving mode.

3. Action (false) : do whatever to turn on the GPS, bluetooth, wifi, set network mode to 4G or anything. Of course, only turn on the one you need. After finish, at the end of this false branch, put action Script : global_networkmode = "Full network". To state that now the phone is in full network mode.

This flow, everytime it executed, will always toggling execute true/false branch. 1st = false, 2nd = true, 3rd = false, 4th = true ..... etc.

of coz, change the name to suit your need, above just example. I have several flows utilize the same concept of toggling. Some of them don't need GloVar, as there other way to check the state of the flow. (such as notification or wifi connected)

Then for the widget, create the size of the widget as needed. Add text element, fill in the text as {global_networkmode}, change the size, fill and other property as needed. At the widget clickable actions, add 1 action, Click : Execute Flows - Network Toggle. Add the widget to home screen. Now every time you tap that widget, it will execute the flow and toggling between Full network and Energy Saving mode. The text will change after the flow executed successfully till the end (action script). You can add some more action to the flow to change the widget property, such as green background when "Energy Saving". But that is optional.
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.

User avatar
Rhonin
Posts: 19
Joined: 08 Apr 2015 05:23

Re: Widget to show and switch 2G/3G

Post by Rhonin » 09 Aug 2017 15:33

First of all a very BIG THX for your detailed description. It has been a long time ago that i created a new flow and the first time that i create a widget :D

I will create it as soon as i find the time and report or ask if there are some questions open...



Cheers

Rhonin
Automagic on rooted Xperia Z3c running on Android 5.1.1

Post Reply