Skip to main content
Known Participant
February 3, 2017
Answered

Open external content on Air As3 App

  • February 3, 2017
  • 13 replies
  • 2180 views

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?

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer kglad

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.


try:

  1. var fileStream_write:FileStream=newFileStream();
  2. fileStream_write.open(file_lista,FileMode.WRITE);
  3. texto.text="FilestreamWRITEactivado\n";
  4. fileStream_write.addEventListener(Event.CLOSE,closeF);
  5. fileStream_write.close();

function closeF(e:Event):void{

  1. var fileStream_read:FileStream=newFileStream();
  2. fileStream_read.open(file_lista,FileMode.READ);
  3. texto.text+="Filestreamreadactivado";
  4. var prefsXML:XML=XML(fileStream_read.readUTFBytes(fileStream_read.bytesAvailable));
  5. // do something here to test if prefsXML is defined
  6. fileStream_read.close();

}

13 replies

kglad
Community Expert
Community Expert
February 3, 2017

that should be WRITE_EXTERNAL_STORAGE

Known Participant
February 3, 2017

Nop, because i have tried with both (read and write) and didn't worked.

Do you see any other possible solution?

kglad
Community Expert
Community Expert
February 3, 2017

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.