Sharing option for text file with extension (or other type of files) - issue #3225

53 views
Skip to first unread message

P5music

unread,
Sep 2, 2020, 4:20:01 AM9/2/20
to CodenameOne Discussions
I want to add the sharing option to my CodenameOne app.
It's going to be possible because there is an filed issue:
I see that it is planned for Version 8 release, if I am not wrong.

I would like to know
-will it be possible to share a txt file with a customized extension, like myfile.ext, so that available apps can share it, email, cloud providers app, and so on?
-is Version 8 coming soon?
-is it possible to add an option to "share" with the filesystem, that is, when the user wants just to leave the file in one of user's folders (in iOS just some folder are under the user control I think).

Thanks in advance

Shai Almog

unread,
Sep 2, 2020, 11:48:43 PM9/2/20
to CodenameOne Discussions
Versions in the system don't mean much since our product is delivered weekly. This feature is scheduled for the next version at this time which means it won't be ready in the next few months as there's a suggested workaround.

You can use URLs to share information between apps by passing data within the URI. This is a common practice and works today on iOS/Android.

P5music

unread,
Sep 3, 2020, 2:50:06 PM9/3/20
to CodenameOne Discussions
Excuse me, what do you mean by sharing information passing data within the Uri?
I need a general sharing option like the Android sharesheet.
What kind of apps could be reached by the Uri? And notice that I have to share a file, not text.

Steve Hannah

unread,
Sep 4, 2020, 8:23:19 AM9/4/20
to codenameone...@googlegroups.com
I think he's probably referring to just calling CN.execute(filePathOrURL)

If you provide a file path, it will generally allow the user to select from the apps they have installed that can open that file type.  Many apps have registered custom URL schemes that will allow you to target those apps directly.  

Steve

Steve

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/0282a911-eb2e-4691-8e52-4102a01c7588n%40googlegroups.com.


--
Steve Hannah
Software Developer
Codename One

P5music

unread,
Sep 4, 2020, 12:59:36 PM9/4/20
to CodenameOne Discussions
Thanks
If I use paths I have to save the file, maybe in a private app folder. Would it work? Would the file be sent as a copy or would the chosen app receive the path or the system format for exchanging (automatic)?
If I use urls, is there a generic url schema to share the file? (at least for a wide range of common apps?)
All this I need on iOS for now.

Shai Almog

unread,
Sep 5, 2020, 12:06:54 AM9/5/20
to CodenameOne Discussions
You need to provide us with more details. Are you sharing between two apps that are yours or with a well known 3rd party app?
If the latter then you need something equivalent to the share API so you can use the native code in the issue.
If the former you can use a URL with base64 encoding and follow the intercepting URLs section of the developer guide.

P5music

unread,
Sep 10, 2020, 5:45:08 PM9/10/20
to CodenameOne Discussions
I need that import/export are symmetrical, so I think that the only option is to hand the user the json text directly to paste wherever it is convenient for  saving/sharing (and viceversa), even if it is cumbersome. 

Some Android features of my app are not available on iOS, I fear, and then they cannot be on CodenameOne too.
Maybe a simpler version of the app is to publish on iOS.
Probably I am going to avoid also the other native features.

Shai Almog

unread,
Sep 11, 2020, 12:04:32 AM9/11/20
to CodenameOne Discussions
I'm not sure I follow this completely. But the general rule is that there are sometimes different ways of doing things on iOS.
You need to find an iOS app that does something similar and figure out what they do.

P5music

unread,
Sep 11, 2020, 8:48:24 AM9/11/20
to CodenameOne Discussions
I see that no iOS system apps can accept my data as URL.
Even if other apps exist that can receive data from my app in such a way, I cannot rely on third party apps on iOS.
Then only option is native code, but I am not going to create native code I think.
Furthermore the app can import, so the user would go through an asymmetrical user experience.
Here's why the text-import/export feature could be useful, I think no other options are left to share/save/backup user data from my app (json array of elements).

Marisole Aromatherapy

unread,
Sep 11, 2020, 9:40:32 AM9/11/20
to codenameone...@googlegroups.com
I can only speak as another CN1 user. Why are you opposed to using native code?

The native code to export csv I shared in the issue is fairly simple. It can be improved and simplified (now I know more obj c than I did when I wrote it. But it works)

I used to dread writing native code (especially obj c). But learning how to add it to CN1 is very liberating, definitely worth the effort :)

Best regards

Javier

Shai Almog

unread,
Sep 12, 2020, 1:06:24 AM9/12/20
to CodenameOne Discussions
Receiving data from other apps is supported via URL which is pretty much the way most apps work. You can also define a supported mime type e.g. https://www.codenameone.com/blog/associating-your-app-with-file-extension-mime-types-iphone-android-windows.html

P5music

unread,
Sep 12, 2020, 5:27:39 AM9/12/20
to CodenameOne Discussions
@Javier
I was amazed by Codename simplicity, the Containers and so on, and just consider what impact has having dialogs that can return any values, instead of being forced to use an intricate tree of runnables like in Android or iOS.
But I developed also a parallel native iOS app in XCode, now it is up to date with the CodenameOne one (sorry for the wordplay), I do not know which will be published, because I am bouncing between the two according to my mind state.
If I have to use native code, well, I have a SwiftUI app that can be finished. It is just a weird language in a weird IDE but I have done almost the same amount of development, and consider that I had to translate from Java code, while CodenameOne just needed some tweaking to existing routines. Despite the simplicity the CodenameOne app it could end up just to be a third version for other platforms or to be purchased by a firm. But I do not know.

@Shai Thank you, I'll have a look at that documentation.

Regards

P5music

unread,
Sep 15, 2020, 3:23:59 AM9/15/20
to CodenameOne Discussions
The url sharing method seems to be the cleanest way to accomplish my goal, in both directions.
But a question of mine was not answered: if I want to use the CN.execute(filePathOrURL) method or similar, where the file has to be so it can be received by the other app? I mean, that url could be in private folders or public folders, and what happens to that file, is it read? with enough permissions?
Thanks

Shai Almog

unread,
Sep 15, 2020, 10:37:15 PM9/15/20
to CodenameOne Discussions
There is no such thing "enough permissions" as the apps are completely isolates from one another in mobile apps.
Share APIs take the file and copy it (or symlink it) to a read-only OS shared location.
Use the App Home typically to store files you want to share.

P5music

unread,
Sep 16, 2020, 2:37:26 AM9/16/20
to CodenameOne Discussions
Thank you for the answer.
If I understand I have to create (to be removed later) a temporary file in the "app home" (I do not know if it is just the private folder, is it?) and then the share API, let's say on iOS, copy it in a shared location to share. Is it possible to know what is that share location or it i just a temp directory?

Shai Almog

unread,
Sep 17, 2020, 12:13:48 AM9/17/20
to CodenameOne Discussions
The OS changes those locations and you don't have access to that location anyway. It isn't a specific directory.

P5music

unread,
Sep 17, 2020, 4:17:32 AM9/17/20
to CodenameOne Discussions
Thanks.
If I am not wrong this is going to be available in milestone Version 8.0.
7.0 is due 20 October, so 8.0 is far to be available.
You said about sharing data within an Url, so my app can receive an entire file this way.
If I am not wrong this is already available in Codename One.
If it works I can use that method both ways. The main concern is about sending data to an application via Url, can you provide an example?
I mean, an Url with an encoded file inside that targets some iOS app?
Regards

Shai Almog

unread,
Sep 18, 2020, 12:11:26 AM9/18/20
to CodenameOne Discussions
Is that app one of yours or an arbitrary 3rd party app?
If the latter you will need a sharing API unless the app has specific support for a URL file.

P5music

unread,
Sep 18, 2020, 3:49:50 AM9/18/20
to CodenameOne Discussions
I have no apps other than this one on iOS, so I want to share a file with any app that can receive generic files.
So I would like to use some generic url scheme, or instead I would like that an installed app among the ones that are on the system from Apple (default apps)
has a url scheme I can use.
The candidate is the File manager app that is nowadays present on iOS, I just want that the app wakes up and can do something with my file, for example asking the user to save it somewhere or share it (handing it to another app). 
But also other ideas are welcome.

Shai Almog

unread,
Sep 19, 2020, 1:43:00 AM9/19/20
to CodenameOne Discussions
For this use case you'd need proper sharing code like the one Javier has contributed or the new API support.
Reply all
Reply to author
Forward
0 new messages