Monitor files and folders on your SD card

Source: Internet
Author: User

The Android System API provides the Fileobserver abstract class (Linux inotify mechanism) to listen to files or folders in the system/sdcard, Fileobserver class can open, create, The move and delete operations are monitored. Here's a look at the code implementation:

Set the file or folder you want to monitor Mfileobserver = new sdcardfileobserver (Environment.getexternalstoragedirectory () . GetPath ());//Start Monitoring mfileobserver.startwatching ();static class sdcardfileobserver extends  Fileobserver {    //mask: Specifies the type of event to listen to, default is fileobserver.all_events     public sdcardfileobserver (String path, int mask)  {         super (Path, mask);    }    public  Sdcardfileobserver (String path)  {        super (path);     }     @Override     public void onevent (int  event, string path)  {        final int  action = event & fileobserver.all_events;         switch  (Action) &NBSp {            case fileobserver.access:                 system.out.println (" event:  file or directory is accessed, path:  " + path);                 break;             case FileObserver.DELETE:                 system.out.println ("event:  file or directory is deleted, path: "  +  Path);                break;             case FileObserver.OPEN:                 system.out.println (" event:  file or directory is opened, &NBsp;path:  " + path);                 break;            case  FileObserver.MODIFY:                 system.out.println ("event:  file or directory was modified, path: "  + path);                 break;         }    }}


Monitor files and folders on your SD card

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.