How to automatically lock the screen or something when the Wi-fi disconnects?


Question

I think this would be useful if you're entering data into a form, but you don't want to accidentally press "submit" when there's no Internet, causing you to have to re-enter everything.



Also, it would be nice for macros. Say you have a macro doing something on an app that requires Internet. When the Internet fails, the macro goes haywire by clicking on random stuff it's not supposed to click. It would be best to lock the screen in that case.



I have Android 4.4.2. I do not have cellular data on this phone.


Answer

Using Macrodroid:




  1. From the drawer, select variable and create a global variable of type boolean. Set it to false and save.

  2. Create a macro. On the Triggers tab, on the Connectivity section, select Wifi Enable.

  3. On the Actions tab, on the Conditions/Loops section, select Repeat actions, then "While condition repeat". On the Condition, go to the Connectivity section, select Wifi State, then Wifi is connected to, finally select Any network.

  4. On the Actions tab, on the Macrodroid specific section, select "Wait Before Next Action", set a time (I set it at 1mn).

  5. On the Actions tab, on the Connectivity section, select Connectivity check. Enter a website that the macro will keep checking if there is an internet connection to it or not. Set the timeout. Click the + and add a variable.

  6. On the Actions tab, on the Conditions/Loops section, select "If clause", under Macrodroid specific, select Macrodroid variable and choose the variable created on the previous section. Set its value to False.

  7. On the Actions tab, on the Screen section, select "Screen On/Off", choose Screen Off.

  8. On the Constraints tab, under the Screen and Speaker section, select "Screen On/Off", choose Screen On.

  9. Give the macro a name and save it.



The macro will look like the image below. Click the up and down arrows on the Actions section, to be able to move the actions up or down.
Click the 3-dot on the top right and select Test Macro.



Lock screen if no internet macro



Explanation: When the macro starts, it checks if Wifi enabled and the device is connected to any network. It waits for a certain time before checking if there is a connection to the website enter in step 5. If after the set timeout in step 5 there is no connection, the screen will be switched off.



The delay in step 4 also serves as a fail-safe mechanism when you switch the screen on again to allow for example to disable the macro.



Note: To see the Conditions/Loops section under the Actions tab, the macro must be saved. Then when opened for an edit, the section will be visible.


Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes