You'll have to bypass FLAG_SECURE with a rooted device or third party app. If you want to use an app instead so you don't have to bypass FLAG_SECURE then I recommend Tasker or AutoInput as they have worked for me in the past.