module to export/import strings on Android (SAF)

grant

Member
CX Code Contributor
3rd Party Module Dev
Joined
Nov 19, 2019
Messages
81
This module uses Android's Storage Access Framework to export/import strings to files. It is useful for letting the user backup their saves on their hard drive or cloud storage apps they have installed. The storage access framework requires Android 4.4. Also some TV boxes have SAF stripped out too! :< If the device doesn't support it exporter.getSupported() will return false. Then I like to fallback to using the clipboard to copy/paste save files. Being able to backup my save is always a must for me.

exportString:Void(content:String, name:String, mime:String)
content = text content of file to make​
name = name of file to create​
mime = mime type of file to create. (Eg: "text/plain", "text/*", "*/*") (Note: Storage Access framework doesn't seem to work well with mime types it doesn't recognize.)​
beginImportString:Void(mime:String)
mime = mime type of file to filter for. (Eg: "text/plain", "text/*", "*/*") (Note: Storage Access framework doesn't seem to work well with mime types it doesn't recognize.)​
getImportedString:String()
get the string from the selected file after beginImportString is called and getImportSuccess returns IMPORT_CODE_SUCCESS.​
deleteImportedString:Void()
Clean up after your done importing the string.​
getImportSuccess:Int()
returns the state of importing a string.​
Const IMPORT_CODE_NOT_DONE:Int = 2​
Const IMPORT_CODE_SUCCESS:Int = 0​
Const IMPORT_CODE_CANCELED:Int = 3​
Const IMPORT_CODE_FAILED:Int = 4​
getSupported:Bool()
returns if the export/import functions are supported.​
Demo: The included demo.cxs will open the system file browser to export or import a string when you tap the screen. It displays the imported string. If it is not supported it will just display that it's not supported.

Install:
  1. extract the zip file inside the modules_ext folder inside your Cerberus X installation folder.
  2. place ExportStringsActivity.java in this path Cerberus/targets/android/template/gradletemplate/app/src/main/java/com/grantojanen/modules/ExportStringsActivity.java
  3. Add this line to the top of your .cxs file
    Code:
    #ANDROID_MANIFEST_APPLICATION="<activity android:name=~qcom.grantojanen.modules.ExportStringsActivity~q android:configChanges=~qorientation|keyboardHidden|screenSize|navigation|keyboard|screenLayout|smallestScreenSize~q/>"

License: zlib/libpng (see included license.txt)
 

Attachments

  • Export-Strings-module-V1.0-for-Cerberus-X-for-Android.zip
    5.4 KB · Views: 14
Last edited:

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
832
Is it possible to use to save photos using this? Cerberus has a save-image-file function but it uses the OS module which is not available to Android. Also, have you worked much with sql?
 

grant

Member
CX Code Contributor
3rd Party Module Dev
Joined
Nov 19, 2019
Messages
81
Yes, it is possible to save all kinds of files. I just coded it originally for files containing text (back in 2017 I think), and I wanted to share it (after porting it to Cerberus X). I really like the storage access framework API, but in my opinion the UI is a really watered down file manager currently.
 

grant

Member
CX Code Contributor
3rd Party Module Dev
Joined
Nov 19, 2019
Messages
81
I worked with MySQL a little (college assignments and incomplete projects). I haven't finished any apps or websites that really need it yet.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
832
But I can't find the zip file?
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
832
Thanks! But I can't get it to compile?

TRANS cerberus compiler V2021-07-25
Parsing...
Semanting...
Translating...
Building...
> Task :app:clean
> Task :app:preBuild UP-TO-DATE
> Task :app:preReleaseBuild UP-TO-DATE
> Task :app:compileReleaseAidl NO-SOURCE
> Task :app:compileReleaseRenderscript NO-SOURCE
> Task :app:generateReleaseBuildConfig
> Task :app:javaPreCompileRelease
> Task :app:checkReleaseAarMetadata
> Task :app:generateReleaseResValues
> Task :app:generateReleaseResources
> Task :app:createReleaseCompatibleScreenManifests
> Task :app:extractDeepLinksRelease
> Task :app:mergeReleaseResources
> Task :app:processRel
easeMainManifest
> Task :app:processReleaseManifest
> Task :app:mergeReleaseNativeDebugMetadata NO-SOURCE
> Task :app:mergeReleaseShaders
> Task :app:compileReleaseShaders NO-SOURCE
> Task :app:generateReleaseAssets UP-TO-DATE
> Task :app:mergeReleaseAssets
> Task :app:compressReleaseAssets
> Task :app:checkReleaseDuplicateClasses
> Task :app:desugarReleaseFileDependencies
> Task :app:processReleaseJavaRes NO-SOURCE
> Task :app:mergeExtDexRelease
> Task :app:processReleaseManifestForPackage
> Task :app:mergeReleaseJavaResource
> Task :app:processReleaseResources
> Task :app:compileReleaseJavaWithJavac FAILED
/Users/user/Desktop/a/exportstrings/demo.buildv2021-07-25/android/app/src/main/java/com/grantojanen/exportstringsdemo/CerberusGame.java:43: error: package com.grantojanen.modules does not exist
20 actionable tasks: 20 executed
import com.grantojanen.modules.ExportStringsActivity;
^
/Users/user/Desktop/a/exportstrings/demo.buildv2021-07-25/android/app/src/main/java/com/grantojanen/exportstringsdemo/CerberusGame.java:3560: error: cannot find symbol
ExportStringsActivity.export_file(content, name, mime, BBAndroidGame.AndroidGame().GetActivity());
^
symbol: variable ExportStringsActivity
location: class exportstrings
/Users/user/Desktop/a/exportstrings/demo.buildv2021-07-25/android/app/src/main/java/com/grantojanen/exportstringsdemo/CerberusGame.java:3564: error: cannot find symbol
ExportStringsActivity.import_file(mime, BBAndroidGame.AndroidGame().GetActivity());
^
symbol: variable ExportStringsActivity
location: class exportstrings
/Users/user/Desktop/a/exportstrings/demo.buildv2021-07-25/android/app/src/main/java/com/grantojanen/exportstringsdemo/CerberusGame.java:3568: error: cannot find symbol
return ExportStringsActivity.get_imported_string(BBAndroidGame.AndroidGame().GetActivity());
^
symbol: variable ExportStringsActivity
location: class exportstrings
/Users/user/Desktop/a/exportstrings/demo.buildv2021-07-25/android/app/src/main/java/com/grantojanen/exportstringsdemo/CerberusGame.java:3572: error: cannot find symbol
ExportStringsActivity.delete_imported_string(BBAndroidGame.AndroidGame().GetActivity());
^
symbol: variable ExportStringsActivity
location: class exportstrings
/Users/user/Desktop/a/exportstrings/demo.buildv2021-07-25/android/app/src/main/java/com/grantojanen/exportstringsdemo/CerberusGame.java:3576: error: cannot find symbol
return ExportStringsActivity.get_import_success();
^
symbol: variable ExportStringsActivity
location: class exportstrings
/Users/user/Desktop/a/exportstrings/demo.buildv2021-07-25/android/app/src/main/java/com/grantojanen/exportstringsdemo/CerberusGame.java:3580: error: cannot find symbol
return ExportStringsActivity.supportsSAF(BBAndroidGame.AndroidGame().GetActivity());
^
symbol: variable ExportStringsActivity
location: class exportstrings
Note: /Users/user/Desktop/a/exportstrings/demo.buildv2021-07-25/android/app/src/main/java/com/grantojanen/exportstringsdemo/CerberusGame.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/user/Desktop/a/exportstrings/demo.buildv2021-07-25/android/app/src/main/java/com/grantojanen/exportstringsdemo/CerberusGame.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
7 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileReleaseJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s
TRANS FAILED: Android build failed.
Done.
 

grant

Member
CX Code Contributor
3rd Party Module Dev
Joined
Nov 19, 2019
Messages
81
Sadly, you need to add a Java file to Cerberus X. Did you do that already? See the "Install" section of the first post.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
832
Thanks! it kind of worked with documents is it possible to get it working with photos and videos too?
 

grant

Member
CX Code Contributor
3rd Party Module Dev
Joined
Nov 19, 2019
Messages
81
Totally, but I only made this module for backing up save files in my games and figured I would share it. The Storage Access Framework is for any file type (or folders on Android 5.0+), and it is usually the recommended why to get files from the users external storage. This is because it doesn't require any permissions and the app only gets access to the file or folder the user selects.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
832
Nice and cloud services comes free so to speak right, so it's kind of loading saving and sharing intent rolled into one, i like it.
 
Top Bottom