3

I'm trying to detect file changes in DCIM/Camera directory. But event doesn't trigger, when I make a picture with camera. I've tried to create a Service to be sure observer didn't close, but it didn't help.

It doesn't trigger even if I copy files into the directory with Explorer on my computer, when phone connected via USB.

And it doesn't trigger if I copy files with ES Explorer on my phone

What am I doing wrong?

I've added <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> to Android Manifest.

Target Sdk version: 28, min: 15

MainActivity code:

public class MainActivity extends AppCompatActivity {

    public final String TAG = "DEBUG";
    public static FileObserver observer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final String pathToWatch = Environment.getExternalStorageDirectory().toString() 
                + "/DCIM/Camera/";

        observer = new FileObserver(pathToWatch) {

            @Override
            public void onEvent(int event, String file) {
                Log.d(TAG, "Event happened!");

                Toast.makeText(getBaseContext(), file, Toast.LENGTH_LONG).show();
            }
        };
        observer.startWatching();

    }
}
tikhpavel
  • 399
  • 3
  • 10

0 Answers0