嗨,我正在创建一个应用程序,该应用程序将检测是否已截取屏幕截图,然后检索该特定屏幕截图。所以我已经能够检测到是否截取了屏幕截图。
但我想知道如何才能获得刚刚检测到的屏幕截图?
这是我的主要活动:
public static File sdDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
public static File f = new File(sdDir, "Screenshots/");
public static String paths = f.getPath();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = getApplicationContext();
directoryFileObserver = new DirectoryFileObserver(paths);
directoryFileObserver.startWatching();
}
这是我的 File Observer 类:
public class DirectoryFileObserver extends FileObserver {
public DirectoryFileObserver(String path) {
super(path,FileObserver.CREATE);
paths = path;
}
@Override
public void onEvent(int event, String path) {
if(path != null){
NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("SCREENSHOT DETECTED")
.setContentText("YOU CREATED A NEW SCREENSHOT");
// Add as notification
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0, builder.build());
}
}
}
在此先感谢您提出任何建议,为我指明正确的方向或提供帮助!:D