0

I'm working on an app that saves thermal images from a FLIR camera to the SD Card on the phone. I'm using Android Marshmallow and I have to use the FLIR SDK.

In the FLIR SDK is a class "Frame". The class has a method "Frame.save", that needs a Java.io.File to save a thermal image: This is from the documentation:

public void save(java.io.File file,
             RenderedImage.Palette previewPalette,
             RenderedImage.ImageType previewImageType)
      throws java.io.IOException,
             java.lang.IllegalArgumentException

Saves a thermal JPEG file, which has a rendered visual preview and embedded thermal data

When I understand it right, on KitKat or higher I have to use the Storage Accsess Framework. So I used it. Send a Intent and get back a Uri to a picked folder on the SD Card. Now to the tricky part. This funktion should create a File and return a Java.io.File that ready for the "Frame.save" method.

public File getJavaFile (String Name, Uri myUri) {


      DocumentFile pickedDir = DocumentFile.fromTreeUri(context, myUri);                      // Document file aus URI
      DocumentFile DocumentFile = pickedDir.createFile("image/plain", Name + ".jpg" );

      File file = new File(DocumentFile.getUri().getPath());
      if(file.canWrite()){
          Log.d(TAG + "/getJavaFile", "File can write");
      }else {
          Log.e(TAG + "/getJavaFile", "File cannot write");
        }

      Log.d(TAG + "/getJavaFile:", "File Created:" + file.getPath());


    return file;
}

The file that the function return is not readable or writeable... Otherwise, when I try to create a File directly, like so:

String root = Environment.getExternalStorageDirectory().toString();
File file = new File(root + "/saved_images");
Log.d(TAG, file.getPath());

Then the the system always gives me this emulated folder:

E/MainActivity: /storage/emulated/0/saved_images

So the question is: How to get a useable Java File, thats stored on the public storage space... Thank you for your time!

  • `on KitKat or higher I have to use the Storage Accsess Framework.` No. Not at all. Unless you want to write to micro SD card. – greenapps Oct 20 '16 at 16:33
  • Misconception two. If you pick a dir by SAF then you cannot use the File class to write a file in that durectory. – greenapps Oct 20 '16 at 16:59
  • For the rest it is pretty unclear what you do and want. Please edit your post and start with the code for the used intent. Then post code for onActivityResult. Please post complete reproducable code. – greenapps Oct 20 '16 at 17:02
  • `/storage/emulated/0/saved_images` What is wrong with this directory? This is the way to go. You can create a File object with `File myfile = new File (file, "thermpic.jpg");` And use `myfile` in the function call. – greenapps Oct 20 '16 at 17:08

0 Answers0