Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9305471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:56:10+00:00 2026-06-18T23:56:10+00:00

I want to know when a file is finished writing, and to do that

  • 0

I want to know when a file is finished writing, and to do that I’m trying to use FileObserver. I’m doing it like this:

FileObserver observer = new FileObserver(imageUri.getPath()) {
        @Override
        public void onEvent(int event, String path) {
            if(event == FileObserver.CLOSE_WRITE)
                Log.d(TAG, "FILE: "+path);
        }
};
observer.startWatching();

imageUri is a valid Uri. When the file is closed I get the following log entry:

FILE: null

Why is it null? It’s possible that the user writes several files, so I need to know which one is triggering the event.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T23:56:12+00:00Added an answer on June 18, 2026 at 11:56 pm

    According to the documentation of onEvent():

    The path, relative to the main monitored file or directory, of the file or directory which triggered the event

    So I guess when path is null it is the the specified file or directory…

    You need to keep track of the original path yourself. And append the path of onEvent() to this path to get the full path (unless you are tracking a file and its value is always null):

    FileObserver observer = new FileObserver(imageUri.getPath()) {
        public String basePath;
    
        @Override
        public void onEvent(int event, String path) {
            String fullPath = basePath;
            if(path != null) {
                // Eventually add a '/' in between (depending on basePath)
                fullPath += path;
            }
            Log.d(TAG, "FILE: "+fullPath);
        }
    };
    observer.basePath = imageUri.getPath();
    observer.startWatching();
    

    I tried to keep the example as close to your code snippet as possible. But, it is much better to create a full-blown class extending FileObserver, so you can add an constructor to store the basePath and are not required to access the public field from outside the class/instance!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use the PHP language for file upload and want to know that the
I want to know how to get mp3 file details like artist, title, album
I want to know what is the use of .properties file and where it
i want to know that why do we add an app.config file in c#
I want to know the differences of File API in html5 and previous version.
I want to know the version of a mp3 file format. What should I
I want to know is it possible to generate .raw file format using C++.
I want to know how to open and manipulate a simple image file in
I want to know if there are any methods other than file.open(); in <windows.h>
I want to know if really 'put' has succeeded in putting the file to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.