In my Android app, I need to detect the screen capture event. How do I do this?
I have used this code in my application and it works fine. It notifies when a screenshot is taken. I have tested it on OnePlus 1, Nexus 6P, Moto G3. No issues on any devices.
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.