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!