Page 1 of 1

Screenshot captured trigger

Posted: 07 Sep 2017 18:43
by Bluscre
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

Re: Screenshot captured trigger

Posted: 09 Sep 2017 12:09
by Martin
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

Re: Screenshot captured trigger

Posted: 09 Sep 2017 13:08
by Bluscre
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 :/

Re: Screenshot captured trigger

Posted: 09 Sep 2017 13:20
by Martin
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.