Google introduced lock screen notifications in Android Lollipop and has allowed users to decide whether or not they want their notifications to show on the lock screen. Tucked away in settings is a menu where you can select to either hide notifications from the lock screen entirely, show that an app has a notification but hide the notification content, or show the notification in its entirety.

But this setting is an all-or-nothing toggle - there’s no way to have it be contextual. If you want to have a setup where notifications are only hidden while you’re away from home, then you’ll have to manually change this setting every time you leave your home. For college students who leave their lock screen on at home and while on campus, you usually just stick with one setting. However, thanks to the power of Tasker, we can have the best of both worlds; show all notification content while at home, but hide notification content while away from home.


Requirements

Although I’m using Tasker here, you’re free to use any other automation app of your choice. Tasker is by far the most popular, and it’s the one most people are familiar with, so that’s what I’m using. SecureTask is a plugin for Tasker that can change the setting we’re looking for, but only after we set it up with the right permission. In order to do that, we need to have ADB access.

Setting up ADB

The first thing you’ll need to do is download the ADB binary for your particular OS. You can do so here. Once you’ve downloaded them, you need to then make sure you have the proper driver if you’re on Windows.

Once you’ve extracted the binary to a separate folder and have installed the driver, we need to next enable USB Debugging on the smartphone. In order to do so, open up Settings and go to About Phone. Tap on Build Number 7 times until you get a dialog telling you that you’ve unlocked Developer Options. You can access Developer Options in Settings now. Apparently in Android O, you have to enter your pin/password before you can open Developer Options. Do so and look for USB Debugging, then enable it.

Now plug in your phone and open up a command prompt in the same directory where you extracted the ADB binary. (Windows users, hold shift+right-click in that folder and select “open command prompt here.”) Type adb devices into the command prompt. You’ll see a message that the ADB server is being started, then on your phone you’ll see a prompt asking you to grant your computer ADB access. Accept it. Now when you enter adb devices into the command prompt, you should see your device’s serial number, if so then you were successful in getting ADB access.

Finally, with an ADB command prompt opened up, enter the following command to grant SecureTask the requisite permission.

        adb shell pm grant com.balda.securetask android.permission.WRITE_SECURE_SETTINGS
    

SecureTask will now have the ability to modify system settings without root access! Now we’re ready to move on to setting up Tasker.

Setting up Tasker

Here is a step-by-step instruction set to make a Tasker profile that triggers when connected/disconnected to/from your home WiFi network, then launches SecureTask to change the setting.

  1. Open up Tasker and tap on the + button in the bottom right to create a new Profile.
  2. Tap “State” to add a State context.
  3. Choose “Net” then “WiFi Connected.”
  4. Under SSID, tap the magnifying glass to bring up a list of saved SSIDs. Choose your home network here.
  5. Press the back key and Tasker will ask you to attach an existing Task or create a new one. Choose “New Task.” Don’t bother naming it.
  6. Once in the Task editing screen, tap on the + icon in the bottom middle to add an Action.
  7. Choose “Plugin” then “SecureTask” then look for “Secure settings” in the list.
  8. Tap on the pencil icon to open up SecureTask’s configuration screen.
  9. For Action, choose “Write.” For Setting enter this exactly as written (without quotes) “secure lock_screen_allow_private_notifications”. For the new value enter “1”. Tap the checkmark when done.
  10. Press back twice to exit to Tasker’s main screen. Now we need to attach an Exit Task that triggers when we disconnect from our WiFi. Long-press on the Task you just created until you see “Add Exit Task.” Tap on that.
  11. Add an Action (same as steps #6-9), except this time for the value enter “0”. This will show the notification on the lock screen but hide its content.

Your phone will now all lock screen notification content while you’re connected to your home network, but hide the notification content when away from home!


Follow the XDA Tutorials RSS feed for more content like this. Download XDA Labs to quickly catch up on all the latest news and original features published on the XDA Portal.