简体   繁体   中英

How do you create a URL for a PDF so that the file can be opened through codename one

I am creating a program using CodenameOne and need to open some PDF files through the app, but every time I try to do this a message pops up saying that it is not a supported file type. The example that they have on the CodemnameOne website is:

devGuide.addActionListener(e -> {
FileSystemStorage fs = FileSystemStorage.getInstance();
String fileName = fs.getAppHomePath() + "pdf-sample.pdf";
if(!fs.exists(fileName)) {
    Util.downloadUrlToFile("http://www.polyu.edu.hk/iaee/files/pdf-sample.pdf", fileName, true);
}
Display.getInstance().execute(fileName);

});

and mine is:

b1L1.addActionListener(e -> {
    FileSystemStorage fs = FileSystemStorage.getInstance();
    String fileName = fs.getAppHomePath() + "PDF TEST.pdf";
    if(!fs.exists(fileName)) 
    {
        Util.downloadUrlToFile("https://files.acrobat.com/a/preview/509b6602-1fd0-4338-8f0d-13836d84e996.pdf", fileName, true);
    }
    Display.getInstance().execute(fileName);
    });

Only the URL is different, so my question is how do you properly create a URL that CodenameOne can recognize? I used the "Send and Track" tool in Adobe Acrobat Reader DC to no success.

It seems you used a space in the local file name which might not work great. But you also need to make sure the link is direct to the file and not a hosting service that hides said file. Keep in mind that the phone might not be connected to the VPN so a URL visible to you on your laptop might be invisible to the phone on its network.

You can use dropbox or a similar solution but make sure to provide a direct link and not a link to a download page.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM