Copy link to clipboard
Copied
Hello everyone!
Since Wednesday i keep searching for the solution of a problem.
My app loads a document from the smartphone SD Card, with this code:
var file_lista:File=File.documentsDirectory.resolvePath("/sdcard/lista.xml");
var fileStream:FileStream = new FileStream();
try {
fileStream.open(file_lista, FileMode.READ);
texto.text="Filestream activado";
} catch(e:Error) {
texto.text=e.message;
}
It gives me the error 3001 - Folder or file acess denied, but i have already written the permission on manifest:
<manifestAdditions><![CDATA[<manifest>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
</manifest>]]></manifestAdditions>
</android>
And it continues to give me that error.
I can't find what's going on.
Can you help me?
try:
function closeF(e:Event):void{
Copy link to clipboard
Copied
that should be WRITE_EXTERNAL_STORAGE
Copy link to clipboard
Copied
Nop, because i have tried with both (read and write) and didn't worked.
Do you see any other possible solution?
Copy link to clipboard
Copied
oh, i didn't even know there was a READ_EXTERNAL_STORAGE, but after looking on Manifest.permission | Android Developers i see there is.
so you need both to read and write.
and the same app that writes would need to read, not different apps.
Copy link to clipboard
Copied
Ok, thank you, but i have both (Write and Read) and doesn't work.
My app doesn't write, just read the file.
i am trying to troubleshoot accessing the file throught another source.
Copy link to clipboard
Copied
i don't think you'll be able to use the same path to read the file unless you the app that writes the file also reads it.
understand?
test by having the xml writing app also read the xml.
Copy link to clipboard
Copied
Ok, now i understood.
I have tried this way and creating two stream variables (one for read stream and another for write stream):
try {
stream.open(file_lista, FileMode.WRITE);
texto.text+="Filestream WRITE activado \n";
} catch(e:Error) {
texto.text+=e.message;
}
try {
stream.open(file_lista, FileMode.READ);
texto.text+="Filestream read activado";
} catch(e:Error) {
texto.text+=e.message+"\n";
}
var prefsXML:XML = XML(stream.readUTFBytes(stream.bytesAvailable));
stream.close();
None of both worked fine.
Now i will try this way:Reading from and writing to an XML preferences file | Adobe Developer Connection
Edit:
var fileStream_write:FileStream = new FileStream();
fileStream_write.open(file_lista, FileMode.WRITE);
texto.text="Filestream WRITE activado \n";
fileStream_write.close();
var fileStream_read:FileStream = new FileStream();
fileStream_read.open(file_lista, FileMode.READ);
texto.text+="Filestream read activado";
var prefsXML:XML = XML(fileStream_read.readUTFBytes(fileStream_read.bytesAvailable));
fileStream_read.close();
This way, does not work either.
Copy link to clipboard
Copied
try:
function closeF(e:Event):void{
var fileStream_write:FileStream = new FileStream(); fileStream_write.open(file_lista, FileMode.WRITE); texto.text="Filestream WRITE activado \n"; fileStream_write.close(); var fileStream_read:FileStream = new FileStream(); fileStream_read.open(file_lista, FileMode.READ); texto.text+="Filestream read activado"; var prefsXML:XML = XML(fileStream_read.readUTFBytes(fileStream_read.bytesAvailable)); fileStream_read.close();
}
Copy link to clipboard
Copied
Thank You!
We have made good progress!
This way, the filestream WRITE, works:
var fileStream_write:FileStream=new FileStream();
try {
fileStream_write.open(file_lista,FileMode.WRITE);
}
catch (e:Error){
texto.text+=e.message;
}
texto.text="Filestream WRITE activado \n";
fileStream_write.addEventListener(Event.CLOSE, closeF);
fileStream_write.close();
But there is something wrong with the listenner.
I am trying to figure it out what.
Thank you, once more!
Copy link to clipboard
Copied
you're welcome.
p.s. make sure fileStream_write is defined outside a function body
Copy link to clipboard
Copied
Unfortunatelly, we are just closer!
It doesn't block but doesn't work either:
It only "fires" an event if i make the stream to be asynchronously.
I have made a listenner for the errors, and guess what: Returns the same error: File/ folder Acess denied
try {
fileStream_write.openAsync(file_lista,FileMode.WRITE);
fileStream_write.addEventListener(Event.COMPLETE, closeF);
fileStream_write.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
}
catch (e:Error){
texto.text+=e.message;
}
texto.text="Filestream WRITE activado \n";
function closeF(e:Event):void{
texto.text="ADS";
fileStream_write.close();
var fileStream_read:FileStream=new FileStream();
fileStream_read.open(file_lista,FileMode.READ);
texto.text+="Filestream Read activado";
var prefsXML:XML=XML(fileStream_read.readUTFBytes(fileStream_read.bytesAvailable));
// do something here to test if prefsXML is defined
fileStream_read.close();
}
Once more, can you help me?
EDIT: I changed manually the smartphone storage options for my aplication have access to storage and dont returned any error!
But doesn't fire closeF either.
Copy link to clipboard
Copied
then use the synchronous netstream and don't use a listener for close.
Copy link to clipboard
Copied
Yey! That way it works!
I have a question:
I need to send every item of my xml to a list.
Before having to load my xml as a stream, i had a listenner that fired when the xml loaded sucessfuly and then save the items with that code:
lista_XML = XML(event.target.data);
for (var i: uint = 0; i < lista_XML.movie.length(); i++) {
texto.text+="Item numero: "+i+", nome: "+lista_XML.movie.nome.text();
item.label = lista_XML.movie.link.text();
item.data = lista_XML.movie.nome.text();
}
Now, what is the best method to do the same?
Add a eventlistenner to fileStream_read and make it asynchronous?
Copy link to clipboard
Copied
read you xml using async
after that code executes execut the code that adds those data to your list component.
(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)
Find more inspiration, events, and resources on the new Adobe Community
Explore Now