Create Sub Directory in ASD on first run?

This code should do it, works if called from a method.

File dir = new File(context.getExternalFilesDir(null).getAbsolutePath(), "imgconv");
if (!dir.exists()) {
dir.mkdirs();
Toast.makeText(context, "dir 'imgconv' created in ASD", Toast.LENGTH_SHORT).show();
}

However in intellij it is not recognising the .exists() test from java.io.file ?

I presume I need to "wrap" this in something ?

What error is IntelliJ reporting?

If I hover my mouse over 'exists'

cannot resolve symbol 'exists'

Same in "Problems"

If same code is inside a method and i hover over 'exists' I get this:

We can see on the screen that the error is gone. Also, check if IntelliJ hasn't automatically added some strange import for File.

The code must be inside a method.

Then how to call a method without "using a method" ?

In javascript i would just write a function then call the function name:

function greetings() {
document.write("Hello World");
}

greetings();

or just simply run the code

document.write("Hello World");

You can place the code in the constructor of your extension class. Alternatively, you can create a function and call it within the constructor.

public class MyExtension extends AndroidNonvisibleComponent {

    private final Context context;

    public MyExtension(ComponentContainer container) {
        super(container.$form());
        this.context = container.$context();

        createFolder();
    }

  private void createFolder() {
  }
}
1 Like

Aha, I was nearly there myself!

Thank you

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.