1

enter image description here

Following code is used to open PDF document through Mobile App. This code is working on Apple and Android phones. But I encounter this issue only on Android Samsung Tab E. Please advise if anyone else has same issue. Does this depend on adobe acrobat software which I have downloaded on my Tablet ? I have tried with 2 different Apps installed on the device to make sure App has enough compatibility with the software.

On opening screen, I provide link to open PDF file and when user opens the file, I will save the file and open it when ever it is needed. This is working on all other devices except on this particular tablet with version 7.1.1. Please suggest

Code to place the file:

Button b = new Button("Terms of Service"); 
b.getAllStyles().setTextDecoration(Style.TEXT_DECORATION_UNDERLINE);                   
b.addActionListener(e3 -> {
try {
FileSystemStorage fs = FileSystemStorage.getInstance();
final String homePath = fs.getAppHomePath();
String fileName = homePath + "Terms of Service.pdf";                            
Util.copy(Display.getInstance().getResourceAsStream(getClass(), "/Terms of Service 
.pdf"), 
fs.openOutputStream(fileName)); 
Display.getInstance().execute(fileName);                            
} catch (IOException ex) {
}
}); 

Code to retrieve the file:

  Button devGuide = new Button("Terms");
  devGuide.setUIID("TextField");
  devGuide.addActionListener(e -> {
  FileSystemStorage fs = FileSystemStorage.getInstance();
  final String homePath = fs.getAppHomePath();
  String fileName = homePath + "Terms of Service.pdf";
  Display.getInstance().execute(fileName);
  });

enter image description here

enter image description here

user1678742
  • 153
  • 1
  • 7
  • Can you provide more details on the OS version of the device? Can you provide the native logs either via DDMS or via this [new approach](https://www.codenameone.com/blog/native-logging-certificate-wizard.html) so we can see what went wrong – Shai Almog Jun 21 '18 at 04:21
  • This is happening on Android Samsung Tab E OS version: Android 5.1 Lollipop. It throws error no permission to secure storage. Do I have to enable any permission for it ? Not Sure. – user1678742 Jun 21 '18 at 17:03
  • I see the file saved somewhere in Tab( SD or local memory) but I'm not able to open the file from Mobile App – user1678742 Jun 21 '18 at 20:37
  • Is the file in the home path? If you invoke `FileSystemStorage.getInstance().exists(fileName)` does it return true? How did you download to the file? – Shai Almog Jun 22 '18 at 04:02
  • It exists because I kept pdf file in the src folder of the project itself. It should available to open for the App. In the App, I want the file to open on click of a button or click on a hyper link. But it is not working. – user1678742 Jun 22 '18 at 14:38
  • It works on iphone and android samsung phone but not working on Tablet with Android 5.1 lollipop version or 7.1.1 version as well. – user1678742 Jun 22 '18 at 15:03
  • The src folder isn't a file on the filesystem. You only show the portion of the code for opening but not the portion of the code that placed the file in that location. Files within the src directory are translated to resource files and arn't accessible via the FileSystemStorage API – Shai Almog Jun 23 '18 at 04:47
  • @Shai.I have updated the code to place the file in that location. In both the places file is not getting opened. .This code works on all other devices except on this device where version Android 7.1.1 present. I see error in the log says : android.os.FileUriExposedException: file:///storage/emulated/0/tmp/Terms of Service.pdf exposed beyond app through Intent.getData() – user1678742 Jun 23 '18 at 20:47
  • Please advise if any changes needed. – user1678742 Jun 23 '18 at 20:47
  • Can you rename the file to not include spaces or special characters everywhere e.g. `TermsOfService.pdf`. I would avoid those as they behave differently in the various OS's. – Shai Almog Jun 24 '18 at 05:16
  • Yes Shai. Even when I change the file name without space, I see the same outcome. Is there any other thing could be the reason for this. Please suggest. – user1678742 Jun 24 '18 at 06:55
  • Is this issue related to this one - https://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed. Please suggest – user1678742 Jun 24 '18 at 07:15
  • Second question, IF I remove the space in the name, when I open the pdf file it show up the name without space. Is there a way I can give alias name for pdf file while displaying. Please suggest – user1678742 Jun 24 '18 at 08:57
  • I have added build hint : android.targetSDKVersion : 23 and PDF is opening now on the same Tablet. When I deploy this to App Store, do I have to keep this build hint or will that work automatically in App Store Build. Please let me know. – user1678742 Jun 24 '18 at 17:45
  • That could be a regression due to the API 27 migration. It seems to be a FileUrlExposed issue. Can you please file a bug on this? – Shai Almog Jun 25 '18 at 04:02
  • Sure Shai. IS there a way I can rename or alias name for PDF file in this scenario? – user1678742 Jun 25 '18 at 05:49
  • With that error it's unrelated to the name. It's something we'll need to fix. I've assigned the issue you submitted and gave it a high priority as it's a regression https://github.com/codenameone/CodenameOne/issues/2461 – Shai Almog Jun 26 '18 at 04:20
  • Got it Shai. Thank You. I have another question related to this, How can I rename the pdf name on the screen. Please refer the screenshot for reference. – user1678742 Jun 27 '18 at 01:49
  • Though file name is without spaces, can i display the name on the header with spaces. Please advise. – user1678742 Jun 27 '18 at 01:56
  • That's the native UI. I think it might work with the spaces after the fix Steve committed but I'm not sure... You'll need to test that. – Shai Almog Jun 27 '18 at 04:20
  • Shai..Shannah and Shai, When would these changes are available in the builds(after july 17th?) . Is there any workaround for PDF before that time. With SDK=23 build hint it works on newer OS devices but not working for older devices. If we release the build to App store will this issue exists for App store builds with build server patch. Please advise. Another issue with SDK=23, first time when it gets to the page where the link to pdf present will display blank white screen- I have to kill the app and reopen it to see the page. second time onward I don't see that issue. Please advise. – Vinod Jun 27 '18 at 22:59

0 Answers0