I have a codenameone class which contains a method of upload a file for mobile app.I want to call that codenameone class method from my javascript function while user click on that upload button.
Below is my codenameone class method which is going to upload a file.
public void actionPerformed1(){
if (FileChooser.isAvailable()) {
FileChooser.showOpenDialog("image/*", e2-> {
String file=null;
if(e2!=null){
file = (String)e2.getSource();
}
if (file == null) {
hi.revalidate();
} else {
String extension = null;
if (file.lastIndexOf(".") > 0) {
extension = file.substring(file.lastIndexOf(".")+1);
}
if ("txt".equals(extension)) {
FileSystemStorage fs = FileSystemStorage.getInstance();
try {
InputStream fis = fs.openInputStream(file);
hi.addComponent(new SpanLabel(Util.readToString(fis)));
} catch (Exception ex) {
Log.e(ex);
}
} else {
hi.add("Selected file "+file);
}
}
hi.revalidate();
});
}
Below is my html file where I will be using javascript to call codenameone actionPerformed1() method.
<pre>
type="button" value="call method"
onClick = "document.FileChooserDemo.actionPerformed1()"
</pre>
What can I do in javascript to call the codenameone method?
Thank you.