我阻止我的应用程序截取屏幕截图。为此,我使用getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
当用户想要截屏时,我收到消息"Couldn't save the screenshot, Stroage may be in use"
。我想根据我的要求自定义此消息。此外,当用户尝试截取屏幕截图时,我想点击网络API。
我使用下面的代码,但没有成功
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")){
Log.e("tag", "Screenshot captured!!");
}
}
h.postDelayed(this, delay);
}
}, delay);
}
答案 0 :(得分:0)
在所有活动中setContentView
之前添加此行代码
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE);