Flash, AS3: Is there a way to obtain the current security settings/restrictions for mic/camera programmatically?
When using a microphone or camera in a Flash application, the user must grant access to the devices in the security settings panel. The decision of allowing access or denying it can be set to be remembered the next time the application will run by checking the "remember" check box.
And when a user has set to "remember" his choice, the security panel will not pop open when trying to access the said devices. But how do we know if access was granted or not?
So is there a way to check if the user has either allowed or denied access to the microphone as well as check if this decision was set to be a one shot or remembered the next time?
This would be particularly useful when the user has denied access previously and set his decision to be remembered. Being aware of this fact lets us display a message telling the user he must click to open the security pane开发者_如何学JAVAl and allow access if he wants to use the application, for example.
Flash easily lets you check the current restrictions and is pretty detailed in what information it lets you have. It's all available in the Camera documentation on the Adobe website but I've posted an example below, hope it helps.
package
{
import flash.display.Sprite;
import flash.events.StatusEvent;
import flash.media.Camera;
import flash.system.Security;
import flash.system.SecurityPanel;
public class CameraExample extends Sprite
{
private var _cam:Camera;
public function CameraExample()
{
if (Camera.isSupported)
{
this._cam = Camera.getCamera();
if (!this._cam)
{
// no camera is installed
}
else if (this._cam.muted)
{
// user has disabled the camera access in security settings
Security.showSettings(SecurityPanel.PRIVACY); // show security settings window to allow them to change camera security settings
this._cam.addEventListener(StatusEvent.STATUS, this._statusHandler, false, 0, true); // listen out for their new decision
}
else
{
// you have access, do what you like with the cam object
}
}
else
{
// camera is not supported on this device (iOS/Android etc)
}
}
private function _statusHandler(e:StatusEvent):void
{
if (e.code == "Camera.Unmuted")
{
this._cam.removeEventListener(StatusEvent.STATUS, this._statusHandler);
// they have allowed access to the camera, do what you like the cam object
}
}
}
}
精彩评论