hi all,

the below program which i got form net. i am able to create the file
a.txt but the onEvent fuction is not being called as the Log.e
(........); is not getting logged.

plz help me out.


*************************************************************start of
the program*******************************************************
package com.home.files;

import java.io.File;
import java.io.IOException;

import android.app.Activity;
import android.os.Bundle;
import android.os.FileObserver;
import android.util.Log;

public class filesystem extends Activity
{
        public static final String TAG="filesystem";
        public FileObserver observer;
        @Override
        public void onCreate(Bundle icicle)
        {
                super.onCreate(icicle);
                setContentView(R.layout.main);
                observer=new FileObserver("\\sdcard\\tmp"){
                        @Override
                        public void onEvent(int event, String path)
                        {
                                Log.e(TAG,"onevent");
                                if(event == FileObserver.CREATE){
                                        Log.e(TAG, "File created [" + path + 
"]");
                                }
                                else if(event == FileObserver.DELETE){
                                        Log.e(TAG, "File deleted [" + path + 
"]");
                                }
                        }
                };
                observer.startWatching();
                File f=new File("\\sdcard\\tmp\\a.txt");

                        try {
                                f.createNewFile();
                                observer.stopWatching();
                                Log.e(TAG,"file created");
                        }
                        catch (IOException e) { }


        }
}

**************************************End of the
program******************************************************************************

On Jan 6, 12:56 pm, "Dianne Hackborn" <hack...@android.com> wrote:
> Use android.os.FileObserver.
>
> On Mon, Jan 5, 2009 at 5:19 AM, pradeep <pradeep...@gmail.com> wrote:
>
> > how to get notifications if i make any change in file system like i
> > add a file or delete a file.
>
> --
> Dianne Hackborn
> Android framework engineer
> hack...@android.com
>
> Note: please don't send private questions to me, as I don't have time to
> provide private support.  All such questions should be posted on public
> forums, where I and others can see and answer them.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to