Hi I am creating an application that would detect if a screenshot has been taken and then retrieve that particular screenshot. So I have been able to detect if screenshots are taken.
But I am wondering how would I be able to get that screenshot that was just detected?
This is my Main Activity:
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();
}
and this is my File Observer class:
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());
}
}
}
Thanks in advance for any suggestions to point me in the right direction or help! :D