/
Android: Saving

Android: Saving

Saving new or existing files require some important actions on the host application side especially where to load and save the files on the device. Some certain locations require special permissions to be set in the manifest. Please find more information about this in the official Android documentation ( e.g. getFilesDir() , getExternalFilesDir(java.lang.String) ). The saving samples always write files to the app specific folders.
Note: Using folders without setting up proper permissions in the manifest may lead to a crash.

Saving files can be invoked by calling system provided commands (SAVE, SAVEAS) or kernel functions, no matter if it is a new or existing file. Existing files have already a real file path on the device the SDK uses for writing but for saving new files it is necessary to setup the setWorkingFolder( … ) provided by the singleton CFxARESInstance.instance(). The SDK will always trigger the callback dialogGetFileName( … ) provided by CFxARESInstanceDelegate, this callback allows the host application to show a custom user interface that allows the user to specify a file name or path or the host application can directly return a fixed location.

 

Existing commands JAVA

Simply using the runCommand() method of the singleton CFxARESInstance.instance().
The final call looks like: CFxARESInstance.instance().runCommand("_SAVE\n");
This execution can be linked with a onClickListener() of a simple Button.

 

Button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SaveDocument(); } }); private void SaveDocument() { String command = "_SAVE\n"; CFxARESInstance.instance().runCommand( command, false ); }

 

Creating a new file can be achieved by calling the command _SMARTNEW but the working folder must be specified beforehand.

 

private void CreateNewDocument() { CFxARESInstance.instance().setWorkingFolder( m_FolderName ); String command = "_SMARTNEW\n"; CFxARESInstance.instance().runCommand( command, false ); }


Custom code - Java Native Interface JAVA C++

The SDK also provides a sample module DocumentCommands that must be loaded once before the any document is created. Loading the module can be done with the following method:
odrxDynamicLinker()->loadApp( L"DocumentCommands" );

The sample module brings a custom save command _CUSTOMSAVE and a custom close command _CUSTOMCLOSE. The custom save command shows how saving a new file can be initiated from the C++ part but enables way more customizing potential. The custom close command shows how a document can be closed without forcing the user to save his changes ( but this might cause data loss! ).

 

Related content