Filechooser on iOS shows temporary file names, open locations with specific file extensions

56 views
Skip to first unread message

BWC

unread,
Oct 17, 2017, 2:27:55 PM10/17/17
to CodenameOne Discussions
If you are experiencing an issue please mention the full platform your issue applies to:
IDE: IDEA
Device: iPhone

Hi, while testing my app on an iPhone, my filechooser shows the name of the file (in this a case an image) as temp_image.jpg. I emailed this image from my phone to my desktop email and its name is listed as XXXXXX.png. 

How can I get the true filename on my device? 

I understand that the simulator designates temporary filenames as well and have seen this post: https://groups.google.com/forum/#!searchin/codenameone-discussions/filechooser%7Csort:relevance/codenameone-discussions/O3c3CLbKJW8/xTn8KtFeCQAJ . Do I need to do something similar? 

Here is my code:

  ActionListener callback = e->{
if (e != null && e.getSource() != null) {
String filePath = (String)e.getSource();
//File newFile = new File(filePath);
String dir = FileSystemStorage.getInstance().getAppHomePath() +"/myApp"
;
FileSystemStorage storage = FileSystemStorage.
getInstance();
storage.mkdir(dir);
Log.
p("" + new File(dir).exists());
List<String> filepathParsed = StringUtil.
tokenize(filePath, "[/.]");
for (int j = 0; j < filepathParsed.size(); j++)
Log.
p(j +": " + filepathParsed.get(j));
Log.
p("last: " + filepathParsed.get(filepathParsed.size() -1));


StringBuilder hi =
new StringBuilder(filePath);
if (filePath.startsWith("file://"))
hi.delete(
0, 7);
int lastIndexPeriod = hi.toString().lastIndexOf(".");
//StringBuilder newFileName = new StringBuilder(filePath);
//hi.replace(lastIndexPeriod - 1, lastIndexPeriod, "/file");
Log.p(hi.toString());
String hmore = hi.toString().substring(
0, lastIndexPeriod -1);
String ext = hi.toString().substring(lastIndexPeriod);
//String[] last = hi.toString().split("/");
String hi2 = hmore + "/file" + ext;/*hi;*/
List<String> last = StringUtil.tokenize(hi.toString(), "/");/*hi.toString().split("/");*/
//FIXME!
if (filePath == null) {
Log.
p("no file was selected");
}
else {
initializeSpinner();
            }


if (FileChooser.isAvailable()) {
FileChooser.
showOpenDialog(".pdf,application/pdf,.png,image/png,.jpg,image/jpg,.jpeg, image/jpeg", callback);
}
else {
Display.
getInstance().openGallery(callback, Display.GALLERY_IMAGE);
}
}

Also: Is there a way to open a native (at least iOS) dialog to open both images and PDF files, instead of only  Display.getInstance().openGallery(callback, Display.GALLERY_IMAGE);  ??

Thanks!

BWC

unread,
Oct 17, 2017, 2:28:59 PM10/17/17
to CodenameOne Discussions
I'm using Intellij.

Shai Almog

unread,
Oct 18, 2017, 12:38:32 AM10/18/17
to CodenameOne Discussions
I'm assuming you only need it for visual impact so you can have a descriptive file name?
If so you might be able to change the cn1lib. Notice that the file chooser API isn't a builtin API but rather an open source cn1lib that you can customize.

BWC

unread,
Oct 19, 2017, 12:25:04 PM10/19/17
to CodenameOne Discussions
Thanks. I need the true file name so I can upload the file and share it. Android build shows the true file name, e.g., IMG59000.jpg, but on my iOS device it shows as temp_file.jpg. Is this difference due to a nuance in iOS or is there a way I can get the true file name for iOS? I tried to tinker with the cn1 filechooser library but haven't had success.

Thanks again.

Shai Almog

unread,
Oct 20, 2017, 2:08:30 AM10/20/17
to CodenameOne Discussions
It's probably available in the info dictionary here: https://github.com/shannah/cn1-filechooser/blob/master/CN1FileChooser/native/ios/com_codename1_ext_filechooser_FileChooserNativeImpl.m#L186

You can probably debug this in xcode and see the content of info to see if there is something you need there and then extract the filename from there.

BWC

unread,
Oct 24, 2017, 11:47:52 AM10/24/17
to CodenameOne Discussions
Thanks.
Reply all
Reply to author
Forward
0 new messages