Screenshot captured trigger

Post your feature requets for new triggers, conditions, actions and other improvements.

Moderator: Martin

Locked
User avatar
Bluscre
Posts: 145
Joined: 31 Aug 2017 13:58
Location: Germany
Contact:

Screenshot captured trigger

Post by Bluscre » 07 Sep 2017 18:43

https://stackoverflow.com/questions/29532502/detect-a-screenshot-android wrote:There is no direct Broadcast Intent to tell you that a screenshot has been taken. Some people here discuss possible options to do so ( like it's done on Snapchat ). One possible option would be to use FileObserver.
But there are "workarounds" like

Code: Select all

public void detectScreenShotService(final Activity activity){

   final Handler h = new Handler();
   final int delay = 3000; //milliseconds
   final ActivityManager am=(ActivityManager)activity.getSystemService(Context.ACTIVITY_SERVICE);

    h.postDelayed(new Runnable(){
        public void run(){

            List<ActivityManager.RunningServiceInfo> rs=am.getRunningServices(200);

            for(ActivityManager.RunningServiceInfo ar:rs){
                if(ar.process.equals("com.android.systemui:screenshot")){
                    Toast.makeText(activity,"Screenshot captured!!",Toast.LENGTH_LONG).show();
                }
            }
            h.postDelayed(this, delay);
        }
    }, delay);

}
From https://stackoverflow.com/a/40218889
Unofficial AutoMagic Telegram Group: https://t.me/automagicforandroid
Check out my other flows here: https://github.com/Bluscream/AutoMagicFlows or here.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Screenshot captured trigger

Post by Martin » 09 Sep 2017 12:09

Hi,

Unfortunately Google removed this capability with Android 8 for apps like Automagic:
https://developer.android.com/reference ... vices(int)

You could also try to use Notification on Statusbar Displayed to see if the 'screenshot captured' notification is posted by the system.

Regards,
Martin

User avatar
Bluscre
Posts: 145
Joined: 31 Aug 2017 13:58
Location: Germany
Contact:

Re: Screenshot captured trigger

Post by Bluscre » 09 Sep 2017 13:08

Martin wrote:Unfortunately Google removed this capability with Android 8 for apps like Automagic:
https://developer.android.com/reference ... vices(int)
Couldn't you just add a "Only working on Android 7.1 and below" notice like you did on some other triggers?
Most people still use 6.0-7.1 when looking at stats
Martin wrote:You could also try to use Notification on Statusbar Displayed to see if the 'screenshot captured' notification is posted by the system.
That wouldn't work since the different saving positions of screenshots on different devices :/
Unofficial AutoMagic Telegram Group: https://t.me/automagicforandroid
Check out my other flows here: https://github.com/Bluscream/AutoMagicFlows or here.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Screenshot captured trigger

Post by Martin » 09 Sep 2017 13:20

Sure, I'll add the notice to the condition in one of the next updates when I made some more tests on Android 8. Probably some other triggers, conditions and actions are also affected by new limitations imposed by Google.

The screenshot saving location will be hard to get since there's no official API available to detect it so you always have to test a few locations and check the timestamp of the files that could contain the screenshot. Using a file observer could work but also requires that you know the potential folders that are used to save the screenshots.

Locked