Reputation: 2464
I have developed an app with Vuforia for iOS and Android, when the app is run for the first time, the user is prompted to authorize the use of the device's camera.
If the user does not authorize the camera, when the user navigates to the "capture" scene, the camera view is black.
I have looked at the Untiy3D Documentation and found the Application.HasUserAuthorization class, but if I understand correctly, this only works on the Unity web player?
How can I check if the user has allowed the use of the camera in Unity3D (c#).
Any suggestions would be greatly appreciated! TIA!
Upvotes: 6
Views: 6871
Reputation: 6587
Application.RequestUserAuthorization
apparently works for any PC or mobile device camera. I am using it and the NatCam plugin for Unity3D on iPhone with the following script to check / prompt for user camera permissions. The while()
loop is to allow them to take their time giving permission.
int cameraPermission = 0;
// Use this for initialization
public override void Start () {
if (!Application.HasUserAuthorization (UserAuthorization.WebCam)) {
// request camera use
Application.RequestUserAuthorization (UserAuthorization.WebCam);
} else {
cameraPermission = 1;
}
// if we don't have permission, wait until we do
while (cameraPermission != 1) {
// wait a sec
System.Threading.Thread.Sleep(1000);
// if user enables preference
if (Application.HasUserAuthorization (UserAuthorization.WebCam)) {
// proceed to start app
cameraPermission = 1;
}
}
// Start base
base.Start ();
}
Upvotes: 0
Reputation: 7824
As a user on Android I get prompted when installing the apk that it will use the Camera, once I accept that is it. As a developer I don't need to check.
This is how I start the camera using Vuforia API.
CameraDevice.Instance.Stop();
CameraDevice.Instance.Init(CameraDevice.CameraDirection.CAMERA_FRONT);
CameraDevice.Instance.Start();
CameraDevice is a Singleton that you can call.
Upvotes: 1