[英]How to catch screen capture event on Android devices?
在我的Android應用中,我需要檢測屏幕捕獲事件。 我該怎么做呢?
我已在我的應用程序中使用此代碼,它工作正常。 它會在截取屏幕截圖時通知。 我在OnePlus 1,Nexus 6P,Moto G3上進行了測試。 任何設備都沒有問題。
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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.