Esempio n. 1
0
        public static void Enable()
        {
            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            if (!HasFlashlight())
            {
                Debug.LogWarning("This device does not have a flashlight");
                return;
            }

            if (!AGPermissions.IsPermissionGranted(AGPermissions.CAMERA))
            {
                Debug.LogError(AGUtils.GetPermissionErrorMessage(AGPermissions.CAMERA));
                return;
            }

            if (AGDeviceInfo.SDK_INT >= AGDeviceInfo.VersionCodes.M)
            {
                TurnOnNew();
            }
            else
            {
                TurnOnOld();
            }
        }
Esempio n. 2
0
        public static void RequestLocationUpdates(long minTime, float minDistance,
                                                  Action <Location> onLocationChangedCallback)
        {
            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            if (minTime < 0)
            {
                throw new ArgumentOutOfRangeException("minTime", "Time cannot be less then zero");
            }

            if (minDistance < 0)
            {
                throw new ArgumentOutOfRangeException("minDistance", "minDistance cannot be less then zero");
            }

            if (onLocationChangedCallback == null)
            {
                throw new ArgumentNullException("onLocationChangedCallback", "Location changed callback cannot be null");
            }

            if (!AGPermissions.IsPermissionGranted(AGPermissions.ACCESS_FINE_LOCATION))
            {
                Debug.LogError(AGUtils.GetPermissionErrorMessage(AGPermissions.ACCESS_FINE_LOCATION));
                return;
            }

            _currentListener = new LocationListenerProxy(onLocationChangedCallback);

            try
            {
                AGUtils.RunOnUiThread(() =>
                                      AGSystemService.LocationService.Call("requestLocationUpdates", GPS_PROVIDER, minTime, minDistance,
                                                                           _currentListener));
            }
            catch (Exception e)
            {
                if (Debug.isDebugBuild)
                {
                    Debug.LogWarning(
                        "Failed to register for location updates. Current device probably does not have GPS. Please check if device has GPS before invoking this method. " +
                        e.Message);
                }
            }
        }
        public static void StartRecording([NotNull] string fullFilePath, OutputFormat format = OutputFormat.THREE_GPP, AudioEncoder audioEncoder = AudioEncoder.AMR_NB)
        {
            if (fullFilePath == null)
            {
                throw new ArgumentNullException("fullFilePath");
            }

            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            if (!AGPermissions.IsPermissionGranted(AGPermissions.RECORD_AUDIO))
            {
                Debug.LogError(AGUtils.GetPermissionErrorMessage(AGPermissions.RECORD_AUDIO));
                return;
            }

            if (_mediaRecorder != null)
            {
                Debug.LogWarning(
                    "Can't start recording while another recording is in progress. Please call StopRecording() to stop previous recording.");
                return;
            }

            try
            {
                _mediaRecorder = new AndroidJavaObject(C.AndroidMediaMediaRecorder);
                _mediaRecorder.Call("setAudioSource", MediaRecorderAudioSourceMIC);
                _mediaRecorder.Call("setOutputFormat", (int)format);
                _mediaRecorder.Call("setAudioEncoder", (int)audioEncoder);
                _mediaRecorder.Call("setOutputFile", fullFilePath);
                _mediaRecorder.Call("prepare");
                _mediaRecorder.Call("start");
            }
            catch (Exception e)
            {
                if (Debug.isDebugBuild)
                {
                    Debug.LogError("Failed to start recording audio");
                    Debug.LogException(e);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Places the phone call immediately.
        ///
        /// You need <uses-permission android:name="android.permission.CALL_PHONE" /> to use this method!
        /// </summary>
        /// <param name="phoneNumber">Phone number.</param>
        public static void PlacePhoneCall(string phoneNumber)
        {
            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            if (!AGPermissions.IsPermissionGranted(AGPermissions.CALL_PHONE))
            {
                Debug.LogError(AGUtils.GetPermissionErrorMessage(AGPermissions.CALL_PHONE));
                return;
            }

            using (var i = new AndroidIntent(AndroidIntent.ActionCall))
            {
                i.SetData(ParsePhoneNumber(phoneNumber));
                AGUtils.StartActivity(i.AJO);
            }
        }
        /// <summary>
        /// Picks the contact from the phone contacts book.
        /// </summary>
        /// <param name="onSuccess">On success callback. Picked contact is passed as parameter</param>
        /// <param name="onError">On failure callback. Failure reason is passed as parameter</param>
        public static void PickContact(Action <ContactPickResult> onSuccess, Action <string> onError)
        {
            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            Check.Argument.IsNotNull(onSuccess, "onSuccess");
            Check.Argument.IsNotNull(onError, "onError");

            if (!AGPermissions.IsPermissionGranted(AGPermissions.READ_CONTACTS))
            {
                onError(AGUtils.GetPermissionErrorMessage(AGPermissions.READ_CONTACTS));
                return;
            }

            _onSuccessAction = onSuccess;
            _onCancelAction  = onError;

            AGActivityUtils.PickContact();
        }
Esempio n. 6
0
        public static void RecordVideo(Action <VideoPickResult> onSuccess, Action <string> onError,
                                       bool generatePreviewImages = true)
        {
            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            Check.Argument.IsNotNull(onSuccess, "onSuccess");
            Check.Argument.IsNotNull(onError, "onError");

            if (!AGPermissions.IsPermissionGranted(AGPermissions.CAMERA))
            {
                onError(AGUtils.GetPermissionErrorMessage(AGPermissions.CAMERA));
                return;
            }

            _onVideoSuccessAction = onSuccess;
            _onVideoCancelAction  = onError;

            AGActivityUtils.PickVideoCamera(generatePreviewImages);
        }
Esempio n. 7
0
        public static void TakePhoto(Action <ImagePickResult> onSuccess, Action <string> onError,
                                     ImageResultSize maxSize = ImageResultSize.Original, bool shouldGenerateThumbnails = true)
        {
            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            if (onSuccess == null)
            {
                throw new ArgumentNullException("onSuccess", "Success callback cannot be null");
            }

            if (!AGPermissions.IsPermissionGranted(AGPermissions.CAMERA))
            {
                onError(AGUtils.GetPermissionErrorMessage(AGPermissions.CAMERA));
                return;
            }

            _onSuccessAction = onSuccess;
            _onCancelAction  = onError;

            AGUtils.RunOnUiThread(() => AGActivityUtils.TakePhoto(maxSize, shouldGenerateThumbnails));
        }