Finally, I figured it out. Prerequisites:
- AIR runtime 24+
- Android 6+
- APK must be published with WRITE_EXTERNAL_STORAGE permission (otherwise it is automatically DENIED - that what I was stuck at)
Then, this code works for me just fine, it displays Android's "Grant Permission" dialog and then outputs GRANTED or DENIED with regard to my choice. The Log class is just a debug panel of my own, you can change Log.log calls to trace or grab it here (it has no dependencies): https://bitbucket.org/thydmitry/ru.delimiter/src/9083fb46ce1c/classes/ru/delimiter/utils/
package
{
import ru.delimiter.utils.Log;
import flash.filesystem.File;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.PermissionEvent;
import flash.permissions.PermissionStatus;
public class Permissions extends Sprite
{
private var F:File;
public function Permissions()
{
if (stage) onStage();
else addEventListener(Event.ADDED_TO_STAGE, onStage);
}
private function onStage(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, onStage);
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
Log.create(this, true);
Log.log("[Permissions Test] started");
Log.log("File.permissionStatus:", File.permissionStatus);
F = File.applicationStorageDirectory.resolvePath("somefile.txt");
F.addEventListener(PermissionEvent.PERMISSION_STATUS, onPerm);
stage.addEventListener(MouseEvent.CLICK, onClick);
}
private function onClick(e:MouseEvent):void
{
F.requestPermission();
}
private function onPerm(e:PermissionEvent):void
{
Log.log("User's decision:", e.status.toUpperCase());
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…