capture permission granted complete event

前端 未结 1 644
时光取名叫无心
时光取名叫无心 2021-01-16 14:43

I\'m creating an app using flash cc. I needed storage permission. It turns out I needed to ask user the permission for using storage devices. I can ask user for permission a

相关标签:
1条回答
  • 2021-01-16 15:00

    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());
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题