How to call fileList() method from Context class?

2.7k Views Asked by At

How do I use the fileList() method from the context class? What am I doing wrong here?

Context conData;
    conData = new Context();
    String[] instrumentFileList = new conData().fileList();

Any help is appreciated

2

There are 2 best solutions below

0
On

Simply change this from

 String[] instrumentFileList = new conData().fileList();

to

 String[] instrumentFileList = conData().fileList();

You have already created instance by this conData = new Context();

If Context is your non activity class then you can use above code. But you just want to use Context of app then you can use getApplicationContext();

0
On

As in Doc:

fileList() : Returns an array of strings naming the private files associated with this Context's application package.

means you should use Context associated with application to call fileList() instead of by creating Context class instance to get list of private files associated with application.

You can get list of files in Activity as:

 String[] instrumentFileList = YourActivityName.this.fileList();