2017년 4월 14일 금요일

file naming in AI2 and name to use when sharing file


I am trying to email a file that my app is creating.  I have called the file in the display screen taav_file.  When I append data to the file I call do a call taav_file .append to file name "measured_data".  When I then try to share the file with the command "call "Sharing1" .ShareFile. File "measured_data" or taav_file.measured_data"  i get Error 2001: The File file//measured_data could not be found on your device.  Please help me understand what name i need to use to call the file for sharing.  Also, if someone can point me to some better documentation for the File function on AI2 I would appreciate it.  The current documentation is unclear to me.

--
the sharing component expects the full path to the file, see also

--
Thanks, but I am still confused.  Can you give me an example of a full path for say a file that is created with the command call "my_file" .append to File "data_file_name".  When I go to share the file i created using the call "sharing1" .ShareFile command, what do I write for the name in the file block?  I tried using a text block with "data_file_name" written in it, but I get the error file not found on device.  However, when I do a call "my_file" .ReadFrom fileName  with a text block with "data_file_name" I can retrieve the information, so the file must be there.  So my basic problem is I am not specifying the correct path in the text block when i try to specify the file I want to share.  Sorry if I am being overly wordy.

--
the full path for a file myFile.txt stored in the root directory is file:///mnt/sdcard/myFile.txt

--
It is still not working.  I made a simple picture to show you how I create the file and then try to call it to read it.  If you could tell me what to enter for the path name I would really appreciate it.  The example below can read the data, but cannot call the file for sharing.

--
with picture attached.

--
you forgot the slash
and if you store in the root directory, remove the /Test_File subdirectory
--
Thank you very much Taifun.  I know understand and the program was able to find the file.

--

IS it possible to share small .mp3 clips through mms in app inventor?


i get an error 2001: the file cannot be found on your device. I'm not sure if this is possible or not?

--
use Do it to find out that value
see also tip 4 here 

Top 5 Tips: How to learn App Inventor

you might want to provide another screenshot including Do it result

--
Thank you so much for responding, but im not sure what you mean(this is my first try at this!). Can you be a little more specific?

--
have you seen the screenshot?

did you try tip 4 of the tips?

--
Sorry i didnt see that link until now. I dont know if this is helps, but 

--
the Sharing component can't share files from the assets of your app
you first will have to copy it onto the device before being able to share it
my file extension could do it, see the Copy method here

The App Inventor Extensions are currently in testing. See the announcement for more information about how to use an App Inventor Extension. 
The extension feature will be in the next App Inventor release...
         
--
Ok i have the beta running now and i imported your extension, but now when i boot up the emulator i get this:

--
after importing an extension, you have to restart the companion app

--
Thank you!! can you take a quick look at my block now cause it still says file cannot be found on my device.

--
the Sharing component expects the full path to the file, which is in your case file:///mnt/sdcard/DirtMcgirt.mp3

--
ok thank you for getting me this far but now what??

--
this works fine for me on Nexus 5, example project attached

are you using the emulator to test?


--
Yes i am, im going to try to connect my phone and see if that works. here is the error.

--
ok this is what i get when i connect my phone, a samsung galaxy note3. It trys to open the blocks but it never can and then thats when this error pops up.

--
I know i did, i also restarted my phone.

--
make sure to use the correct companion app on that device
You have to use the extension test server together with the corresponding companion app. You can download the companion app from the Help menu - Companion information.

--
YESSS!!!!! thank you so much after i downloaded that app that fixed the error. It still was telling me it couldnt find the file but once i changed the path to whats in the picture, it worked!!!!!!

--
this will work like this only on your development device, because the App Inventor directory with the assets only exists there
also it does not make sense to copy a file from the assets to the assets, actually you will get a warning for that from the Copy method
see again my example in this thread how to do it

--

Help with sharing component


Hi everybody, i have a issue with sharing component. Well that i want to do is the following:
i have a button, when i press this button i want to share a photo and a message, so, i write the path of the photo that i want to share and the text of message... but in some phones this works and in others doesn't work.. because the path isn't the same in all phones. (view the example attached)
Well, how could do this to it work in all phones?
Thanks so much, and sorry for my english, i'm learning english...little by little hahaha

--
you can't share files uploaded as assets into your app
your example only works on your development device...

--
Thank, but isn't it that i want

I want to share a picture which i have uploaded to the project. Not pick a picture from gallery or storage. 
How could do this?

--
you could first save it on sdcard using the Canvas.SaveAs method, see also here
and then share it

--
Okay, so i save the image of canvas and then i share it, putting the path where the image of canvas it was saved?
And one thing more, after i have saved the canvas image and i've shared it, i could delete the canvas image from storage? If it is possible, how can i do it?
--
Okay, so i save the image of canvas and then i share it, putting the path where the image of canvas it was saved?
that sounds like a good idea... just try it...
remember: the sharing component expects the full path to the image, which starts with file:///mnt/sdcard, see also How to take a picture or pick an image and share it

And one thing more, after i have saved the canvas image and i've shared it, i could delete the canvas image from storage? If it is possible, how can i do it? 
as far as I know, this unfortunately is not possible

--
I will try this. What is the default path where canvas image is saved?
And i don't know if in the all of phones will be same, for example: may be in one phone the image is saved in one path and in other phone is saved in a different path...
PD: Wow, i like so much this forum, is very helpful to help everyone to solve his issues. All of my problems and break-heads have been solved here, nice ;)

--
I will try this.
great idea!

What is the default path where canvas image is saved? 
the default path is the root directory of the sd card

And i don't know if in the all of phones will be same, for example: may be in one phone the image is saved in one path and in other phone is saved in a different path... 
it is you who defines in with path it will be stored in the Canvas.SaveAs method...
btw. it also helps to take a look at the documentation http://ai2.appinventor.mit.edu/reference/components/animation.html#Canvas



text SaveAs(text fileName)
Saves a picture of this Canvas to the device's external storage in the file named fileName. fileName must end with one of .jpg, .jpeg, or .png, which determines the file type.

see also tip 2 here 

--
Well...if the canvas image save the image in the root of sdcard the path to obtain the image is:
file://mnt/sdcard/icon.png
And it is valid for all the devices and all the versions of Android?


--
yes

--
i have ben trying but it doesn´t work. The app give an error:
"Runtime Error, width and height must be > 0"
I don´t know why i have this error, attached give you the blocks.


--
the canvas must be visible and width and height must be > 0

--
Ahhh okay, that is the problem. I had the canvas no visible...
But i don't want have the canvas "visible"
How can do i it? Have any other way?

--
Try make the canvas visible just before save and then hide it again straight after save.

--
Not...I have been trying a few of blocks and ways and isn't working.
Someone could help me with my issue...?
Thanks to all for answer :)

PD: I leaved attached the image with the blocks


--
probably a timing issue? you can use a clock component as solution like this:

set the canvas visible and start the clock (test with a timer inveral of 10milliseconds)
in the clock.timer event first save the canvas, then set the canvas visible = false again and share the image

--
Yes, now it's working! : D
Finally, they are in no way to hide the canvas When the timer put it as "visible" for 10 milliseconds ?

PD: I'm testing the application, and the first time When playing the button " Share " canvas image is saved but the application subject me as "Can not find file: // ......" and the application does not share the image
And the second time , when I touch the button " Share " is a work perfectly, and save and share the image well
I don't know why it happens this... Any ideas?
-- 
they are in no way to hide the canvas When the timer put it as "visible" for 10 milliseconds ?
as already said, the canvas must be visible, but you can try a timer interval of 0 or 1 millisecond

 the first time When playing the button " Share " canvas image is saved but the application subject me as "Can not find file: // ....
use a second clock and wait a little bit again before sharing

--
Finally, i have done, with two clocks :)
Thanks you so much, when i finish the app i will mention you on the credits, i promise.

--

Cant share image, error 2001 file not found


Im new to this, but some how i dont get the sharing to work.
I have read many topics such as file:///nmt/sdcard   etc.....

Im now back to the cat and try to share the kitty.png to ex, twitter, facebook etc...

Can some one make an exampel that works.

1) upload the kitty.png



Sharing kitty.png
--
see this thread: Help with sharing component

It does not look like you have used the forums yet, as a search using the search box above would have returned several threads about this topic.

Advice: Before posting, it's a good idea to search in this forum. Many others have likely run into problems similar to yours. How to search see screenshot.

Error 2001 when trying to share a photo


The way I have my app programmed is that you can share photos with people using the share function, when I select an image using the image selector, here is a link to a screen shot of what happens on the phone 

and here is a screenshot what the code looks like 


-- 
You don't have to use the block ImagePicker.Image to specify the image selected. That is the image of the button.
The block you want to use is ImagePicker.Selection.

--

error 2001


..need to share the camcorder file after camcorder records but i keep getting error 2001



--
the result from the camcorder unfortunately is a video content uri, but not a path to the recorded clip and for the sharing coponent you wil need the path to the file
and unfortunately there also is no conversion block available, which converts a video content uri into a path to the file

however you could write your own extension and create a block yourself...

more information about how to create an extension see here https://groups.google.com/d/msg/mitappinventortest/Ip2AX036d0U/5NJlAEbFCgAJ
however that will be more advanced and will require some Java skills...

I also can offer to write that conversion block for you. In case you like to be the sponsor of that block, please contact me by email. Thank you.

--
The correct path to the video clip is content://media/external/video/media/7290
The Sharing component ShareFileWithMessage procedure is adding a file:// prefix to that path which is causing an error.
That results in the incorrect file://content://media/external/video/media/7290 path.
This may be a bug.

--

can't share a saved document


Hello my name is Arjen and i am new in this forum.
My problem is that I am not able to share a saved file from my Samsung Galaxy phone and/or SD-card
As soon as I try to share a test.txt, I get an error message:
Error 2001: The File file://test.txt could not been found on your device. For some reason I cant get the proper path. (have tested also file:///mnt/sdcard/test.txt gives the same error)
The test.txt file is directly stored on the SD-card and not in any directory, is I store it internally on the phone, same problem and error message.
What is going wrong?
--
You cannot read a file on the SD card, only on the internat SD card. Did you look with a file browser what the real filename is?
I assume you read the documentation? Cheers, Ghica.


ReadFrom(text fileName)
Reads text from a file in storage. Prefix the filename with / to read from a specific file on the SD card (for example, /myFile.txt will read the file /sdcard/myFile.txt). To read assets packaged with an application (also works for the Companion) start the filename with // (two slashes). If a filename does not start with a slash, it will be read from the application's private storage (for packaged apps) and from /sdcard/AppInventor/data for the Companion.

--

hello Ghica, thanks for quick response.

Yes i read all the documents and i am storing the file after creation in the internal SD-card in my phone 

--
I have seen that the name in the share file is not correct, even after changing it io text.txt still same problem

--
you have to use the full path for the Sharing component like this file:///mnt/sdcard/text.txt

--
I have to apologias for not responding on your messages. I was working outside and had no internet connection.
Thanks for your input, I can store now in my internal memory of my telephone. Storing on the SDcard is for some reason not possible.
If I use the command “/text.txt” it is stored in the root and if I use “text.txt” it is stored in the app inventor directory.
the share problem is also solved!
--

Why UPDATE function works on Fusion Tables only if I write rowid manually?


I finally completed my app working with Fusion Tables, but if I use a global variable to set ROWID it doesn't works!!! If I write manually ROWID in the blocks It works!
Do You know how can I fix the problem?
--
It might be informative for you to right-click-DoIt on the
JOIN and the GET GLOBAL ROWID block in it.4

--
I see now.

You shouldn't call your aggiorno procedure until the rowid has arrived.
Move the call to the GotResult block where the global receives its value.

--
as ABG said, and if you check the result from the fusiontable, you will realize, that you will get a result like this

rowid
103

which means, you first have to extract the rowid (in the example 103) and then continue with the update statement

to extract the rowid, just use the split block and split at \n (new line) to get a 2 items list, then select the 2nd item, which is the rowid

--
Ok, error is only this. When I find ROWID, the variable contains "rowid xxxx". How can I delete the first part and use only the number?

--
Use the segment block from the text drawer.  You know it'll say rowid and a space, then the number, so start your segment at 7 and go to the end (length of the string - 7).

--
Taifun's idea is more robust.
It protects you against counting errors
and  from having to figure the length of the rowid string.

--
you might want to READ again my previous answer in this thread...

--
@Enis: it is something like this rowid\n103 ...

--
Have I to set \n in the variable settings?

--
On second thought, I did not factor in 
the '\n' learning curve in my robustness estimate.
...Waiting to see how this pans out.

--
Ok, It works at 99%. Finally i have the ROWID in the "global rowid". When have I to call update procedure?

--
what about doing the update after you received the rowid?

--
see screenshot

and: I would use a global variable to indicate, what kind of action you are executing
before selecting the rowid, set that variable to "select" and before doing the update set that variable to "update"
then you can check in the FusiontablesControl.GotResult event, which action you are executing (if-then-else statement)...

if action = select
then get the rowid and call the update procedure
else do something else

--
I tried yet and now. It doesn't work. Now I'm trying to generate apk.

--
I just have seen, you are using a second fusiontable controls component, which means, you do not need my action variable...
check your update statement...
this probably can help

--
Now I try with one FusionTablesControl. The 2nd was only an experiment.
I HOPE IT WORKS!!

--
It doesn't work and the app runs in an infinite loop...
I hope You can see what's the problem.


--
If you are asking for help, I recommend you to make it as easy for others to be able to help you ...
You probably will get more feedback then...

which means in your case post a screenshot of your relevant blocks...


To download the aia file, upload it to  App Inventor, open it, do some bug hunting for you, etc... this takes time, and most people will not do that...

--
Ok, You have a screenshot of my blocks and this is a screenshot of results.

And It goes around and around and around...
--
I can't see a screenshot of your current blocks?
you said, you removed the 2nd fusiontable controls component
in this case you should read this again else you will get an endless loop...

--

--

oh yeah...unfortunately you did not follow any recommendations...I only can recommend you to restart from the beginning...

For UPDATE statements the first step to be done is to get the ROWID of the row to be updated with a SELECT statement. The second step is to do the UPDATE.


--
There's no reason to restrict yourself to just one Fusion Tables (FT) control, right?

Imagine you had a factory assembly line with dumb workers that only knew 
how to do one small task before passing the work onto the next worker.

If you had a FT control named FT_UPDATE_Part1 that only got the ROWID,
you could have its results received block set up the UPDATE statement for
use by the next worker (FT control), FT_UPDATE_Part2.

That simplifies the code and the process flow.

--

"Invalid Query" error when trying to update a record in a Fusion Table


I am getting the following error:

Invalid query: Parse error near '2001' (line 1, Position 81).  for the following UPDATE statement:

UPDATE <table id key> SET userid='admin2' WHERE rowid=2001

The parse error occurs with the rowid that I saved when the record was accessed earlier.    I have tried putting quotes around the rowid value, but that generates another error stating that only numbers and underlines are allow in the value.

Thanks for your help on this!

--
how do you extract the rowid? probably there is an invisible \n included?
why this can happen and how to do it correctly, see also here: Why UPDATE function works on Fusion Tables only if I write rowid manually?
see also

--
I extracted the ROWID from the queried record.

The SELECT QUERY was as follows:

SELECT rowid,userid,password,organization,delimiter FROM <table id key> WHERE ....

I then parsed the record on the string ",delimiter",   The parsed the data record on commas (",").

You could be right regarding the newline character.   I will try parsing the header record from the data record on newline to see what happens.

Thank you for the suggestion.    I will let you know.

--
just for a test I hard-coded the ROWID=2001 into my UPDATE query.   I get the same results as I initially reported.

--
The "Do It" test produced no errors.

--
It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

--
I have made a simplified App to isolate the Fusion Table UPDATE query problem. All of the code for performing the UPDATE is in the logic for one button.

The ROWID for this test is: 3001.   This value was retrieved and stored when the App initialized.  Below is a screen shot of the button logic to perform the update.  I have used a text box for diagnostic information to try to see the problem.
Below are 2 screen shots of the Application.   The information in the text box is what is most significant.  The first screen shot the text box contains information for the record to be updated.   This is when the record id (rowid) is captured and saved.
The next screen shot shows the text box with both the UPDATE query string (built in the click event for the button logic above.  The text box also shows the results of the UPDATE query.
--
What's the purpose of the FORGET LOGIN  call immediately after sending the UPDATE
and before any response can  arrive?

It looks rude.

--
I'm not sure, if the trim block can remove the invisible \n in the rowid

I extracted the ROWID from the queried record.
The SELECT QUERY was as follows:
SELECT rowid,userid,password,organization,delimiter FROM <table id key> WHERE ....
I then parsed the record on the string ",delimiter",   The parsed the data record on commas (",").
my suggestion to get the rowid is to convert the result of your select query in to a list of lists
set myList to list from csv table get result

and then select the rowid (which is the first item in the second sublist) like this

set firstDataRow to select list item myList
                             2

set rowid to select list item firstDataRow
                                        1
--
In my original project I extracted the rowid exactly as you suggested.

If you look at the first screen image (from my phone) it shows the record id (rowid) as 3001, right below it I verified that its length is 4 (i.e. there are no hidden characters in the rowid string.

--
as far as I know, the rowid does not need to be quotified...
but it's worth a try 

... WHERE rowid = '3001'

--
I have tried it both ways .... with quotes it tells me that only numeric values are expected for the value.

--
If you look at the first screen image (from my phone) it shows the record id (rowid) as 3001, right below it I verified that its length is 4 (i.e. there are no hidden characters in the rowid string.
post a screenshot of your blocks after receiving the result of the select statement and how you extract the rowid

 I verified that its length is 4 (i.e. there are no hidden characters in the rowid string.
I think, the invisible \n does not have any length...

--
Screen image of SELECT query parsing block ....
temp - receives the split (parsed) result of the SELECT query - parsed on newline (\n).   This should have removed all newline characters.
         temp has a list of the returned records: List item 1 - header record; List item 2 - the data record including the rowid.
rec - string that has record number 2 in it (a CSV string)
userrec - is a list - it contains the split (parse) record 2 (rec string) - parsed on commas (,)
global recid - receives the first item of the userrec list; this should be the rowid returned with as part of the SELECT query

global recid is used when build the UPDATE query string segement "rowid=" + global recid


--
Is that trailing blank in your SQL UPDATE join necessary?

--
No.  It is not necessary.   I have tried not having it in the join, I have put a space in that string, and I have tried a semi-colon (;).   None of these seem make any difference on the problem I am experiencing.
--
instead of using the split blocks, try the list from csv table block as recommended

my suggestion to get the rowid is to convert the result of your select query in to a list of lists
set myList to list from csv table get result

and then select the rowid (which is the first item in the second sublist) like this

set firstDataRow to select list item myList
                             2

set rowid to select list item firstDataRow
                                        1
--
Just as a test I downloaded the PizzaParty app and test it.   This app INSERTs records without problems into my linked Fusion Table.  However, when I modified this app a bit to UPDATE one of the records I get the same error as we are tracking in this post dialog.

--
OK ... I replaced the "split" on comma block with the "list from csv".   The extracted rowid from the new list is the same (no change); and the Invalid Query error still persists at the same location.

--
do you have any examples of an UPDATE query that works correctly?  If so please send me the aia file for the project and/or test code.

--
No doubt about it, Fusion Tables are weird. In your shoes, I would check the fusion table itself to make sure the rowid hasn't changed, which it will do if you re-insert rows or, sometimes, when you delete some. Next I would try using ROWID instead of rowid. I know it doesn't make sense, but rowid seems to work intermittently while ROWID always seems to.

I always, quote-out the row id.

Are you using the FusiontablesControl? If so, the key should not be included in the query. the error reads, "near 2001&" so I'm thinking that may be the problem. Put the key in the block that AI2 has for it.

--
an update statement like this

UPDATE 1Ty90w_LWJEgZHNwEWgoebigLDEXPYLAgJHVHSFkk SET Date='11.02.2015 16:23:59', Pizza='Pepperoni', Drink='Cerveza', Comment='and beer' WHERE ROWID='2001'

worked fine for me (note: the rowid must be quotified)

--
Paul: Thank you for the suggestions.

The API Key (I assume that is the Key you referred to) is set with at different block, it is NOT part of the SQL UPDATE string.

The strange number you see in the query example in the Table ID number (i.e the table name) for the query.

I will test variations of ROWID and rowid again, but I think I have already done this.   I will let you know.

--
THANK YOU!!   What finally worked was as you suggested:   UPDATE ..... WHERE ROWID='3001' (rowid in caps and the number in single quotes.

--
Thank you for your suggestion, I also had the same suggestion from Paul LeChef in post right before yours.   The proper syntax for and UPDATE query is:

UPDATE ..... WHERE ROWID='3001' (rowid in caps and the number in single quotes.)

Thank for you patience and diligence in tracking this problem down.    It would be helpful if the documentation for the FusionTable control included this.   I am going to mark this problem as "closed."

Thanks to everyone who got involved!!

--
see also the fusiontable documentation https://developers.google.com/fusiontables/docs/v1/sql-reference#updateRow

<row_id>The ID of the row you want to update. A quoted string. To get the row ID, perform a SELECT before the UPDATE.

--