2014년 12월 28일 일요일

Help with sharing text file


I've lurked around for a while and tried the several solutions you provided, but I wasn't able to reach the simple objective to write in a file and share it.
With the solution I'm attaching here I'm able to make it work on the emulator, but on my device it doesn't find the file...

Is there a way to create a file and "get" his full path information without having to set it by code? In this way it wouldn't become dipendent by the device...
-- 
the blocks look fine, well, I first would save the file and then append something...
did you try to manually create a text file in the root directory of your sdcard and then use the sharing component to share it?
Does the following snippet work for you?

--
Sorry for the late answer, but I wasn't on my pc during these holidays.
Saving before sharing seems to work: in attach you will find the new situation... the only backdraw is that you're forced to write in the file before sharing it, while I'd prefer append each time.
To better explain, in my example I will see only "Sharing" on the text file, not also the previous texts...

-- 

well, if you use the File.Save block, everything which was saved before in that file will be overwritten, you probably like to use the AppendToFile method instead?


AppendToFile(text text, text fileName)
Appends text to the end of a file storage, creating the file if it does not exist. See the help text under SaveFile for information about where files are written.
.
SaveFile(text text, text fileName)
Saves text to a file. If the filename begins with a slash (/) the file is written to the sdcard. For example writing to /myFile.txt will write the file to /sdcard/myFile.txt. If the filename does not start with a slash, it will be written in the programs private data directory where it will not be accessible to other programs on the phone. There is a special exception for the AI Companion where these files are written to /sdcard/AppInventor/data to facilitate debugging. Note that this block will overwrite a file if it already exists. If you want to add content to a file use the append block.

--
Yes, as you can see in my blocks is what I've done... the problem is: why have I to explicit do the .SaveFile before sharing? Why cannot I share the file withous saving it again? Or, why is there not a .SaveFile without the text part?

--
why have I to explicit do the .SaveFile before sharing?
you do not have to
Why cannot I share the file withous saving it again?
you can
Or, why is there not a .SaveFile without the text part?
why would that make sense?

coming back to your blocks:
after clicking btnWrite, the text in the file is Saving
after clicking btnShare, the text in the file is Sharing


if you use the File.SaveFile block, everything which was saved before in that file will be overwritten

-- 

why have I to explicit do the .SaveFile before sharing?
you do not have to

Well, in the first example I provided it didn't work without doing it... and you suggested that too :)
coming back to your blocks:
after clicking btnWrite, the text in the file is Saving
after clicking btnShare, the text in the file is Sharing
if you use the File.SaveFile block, everything which was saved before in that file will be overwritten
Yes, that is clear... but what I wasn't able to do in my first example was to save some things in appending on the file and the just sharing it without having to save again...

--

why have I to explicit do the .SaveFile before sharing?
you do not have to
Well, in the first example I provided it didn't work without doing it... and you suggested that too :)
my suggestion was to first save and then append
if you do it the other way around, everything which was saved before will be overwritten

I just tried it myself and I think, we have a timing issue...
this (see screenshot) results in error 2001, the file can't be found on this device, but after checking with a file manager, the file is there

this works


alternatively you also can try use the clock component and share the file 100 milliseconds later

--
I just tried it myself and I think, we have a timing issue...
alternatively you also can try use the clock component and share the file 100 milliseconds later
Uhm... that can be an idea.
Thanks a lot, I'll try this one :)

--
Excellent, with the delay it worked.

-- 
I added an issue to implement an filer even to indicate when the file has been written;  the output side equivalent to Filer.GotText

--

댓글 없음:

댓글 쓰기