Discover Android Screenshot

In recent years, I have been programming on Android, and I am wondering: how to determine when a user takes a screenshot? I want that when the user takes a screenshot, we move on to the next step. I tried the method of intercepting an event, but there is a problem: when the device falls asleep, for example, an event interception occurs. Do you have a solution to capture only screenshot events or ignore another event?

Thanks for the help!

+7
android events screenshot detect
source share
2 answers

There is no direct direct translational intention to tell you that the picture was taken. Some people here discuss possible options for this (as is done on Snapchat). One option is to use FileObserver .

+12
source share

Here is my hack to get notified when a picture is taken.

 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); } 

Tested on Oneplus 2 and Moto E.

Update:

This finally did not work for me, and I ended up using ContentObserver by post type.

+7
source share

All Articles