I want to create instance of native android File class.
For that I have used following code
AndroidJavaClass fileClass = new AndroidJavaClass("java.io.File");
AndroidJavaObject fileObject = new AndroidJavaObject("java.io.File");
But after seeing java api, I found that File class contains one argument in constructor no constructor with empty argument available.
In unity, I don’t know way to pass argument within constructor and I want to use FIle class instance variable.
Please give some guidance in this.
According to Unity - Scripting API: AndroidJavaObject.AndroidJavaObject, you can pass arguments when you create an AndroidJavaObject. The examples show how this would work.
The AndroidJavaObject accepts a list of arguments as it’s second parameter, which should allow you to call whatever version of the File class constructor that you’d like.
The following code:
AndroidJavaObject fileObject = new AndroidJavaObject("java.io.File");
Is equivalent to calling this Java code:
File fileObject = new File();
The AndroidJavaObject constructor allows passing parameters that will be in turn passed along to the Java constructor.
So, in order to initialize a File object, pass the correct constructor arguments, e.g:
// Call the File(string path) constructor
AndroidJavaObject fileObject = new AndroidJavaObject("java.io.File", "/some/path/somePath.txt");