7 Replies Latest reply on May 20, 2016 6:26 AM by Jon-Luke West

    EHS is stopping application from writing to external storage?

    Jon-Luke West

      We have Enterprise Home Screen v2.3 installed on an Android MC40 running KK.  When we are trying to write to a file on the sdcard from within our application, no errors or exceptions are thrown in code and everything looks as if the file has been created, but it isn't.  No file is created.  I have tried this on a TC55 running KK without EHS, and it works as expected.  The file is created and written to correctly.

       

      We are writing to /sdcard/ (the public external storage directory)

       

      I cannot find any options in the EHS config that restrict the ability to write to external storage, but everything seems to be telling me that is exactly what is happening.  Is there an option I am not seeing in the user guide?  What is restricting me?

       

      Thanks.

        • Re: EHS is stopping application from writing to external storage?
          Andreas Fauerbach

          Hi,

           

          EHS does not prevent yor app from writing to external storage.

          However, Android changed external storage access with KitKat:

           

           

          When your app uses it's private storage folder(s), you should have no issues.

            • Re: EHS is stopping application from writing to external storage?
              Jon-Luke West

              Thank you for your response and sharing this bit of information.

               

              I'm a little confused about that image.  I remember seeing it and learning it while at AppForum, but I'm led to believe I can still do this according to Android Developers documentation:

               

              I am using

               

              File file = new File(Environment.getExternalStoragePublicDirectory(""), filename);
              

               

              per Android Developer guidelines (https://developer.android.com/training/basics/data-storage/files.html#WriteExternalStorage), and am checking for write permissions before hand with

               

              public boolean isExternalStorageWritable() {
                String state = Environment.getExternalStorageState();
                 if (Environment.MEDIA_MOUNTED.equals(state)) {
                 return true;
                }
                 return false;
              }
              

               

              which returns true.

               

              and have requested appropriate permission with

               

              <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
              

               

              This tells me that something on the MC40 is stopping my application from writing the file but not on the TC55.

               

              To further strengthen that hypothesis; it works without any problems on the TC55 with KK.  The only 2 apparent differences between the devices, that I have identified, are the device type (MC40) and the fact that EHS is installed

               

              Am I incorrect in this understanding?

               

              I am going to uninstall EHS and try the operation again to satisfy my curiosity.

               

              Thanks again.

                • Re: EHS is stopping application from writing to external storage?
                  Jon-Luke West

                  After uninstalling EHS on the MC40, the application works as expected.  The file is created and written to with no errors at /storage/sdcard0 (which is what was returned by getExternalStoragePublicDirectory)

                   

                  This tells me, rather conclusively, that EHS is preventing my application from writing to my files.

                   

                  I am using the recommended method for writing to a file according to Android documentation:

                   

                  private void submitToFile(Stringtext, String filename) {
                          FileOutputStream outputStream;
                  
                  
                          File file = new File(Environment.getExternalStoragePublicDirectory(""), filename);
                  
                  
                          try {
                              if (file.createNewFile()) {
                                  outputStream = new FileOutputStream(file);
                                  outputStream.write(text.getBytes());
                                  outputStream.close();
                              }
                          } catch (Exception e) {
                              e.printStackTrace();
                          }
                      }
                  
              • Re: EHS is stopping application from writing to external storage?
                Pietro Francesco Maggi

                Hi Jon-Luke,

                no errors and no exception in logcat?

                that sounds very strange.

                 

                As Billie suggested, the best option is to build a small app that reproduce that issue and open a support case.

                 

                You can share the sample app even here, so we give it a try.

                 

                Ciao

                ~Pietro