/// <summary> /// Requests the required runtime permissions for your application. /// </summary> /// <param name="permissions">Permissions to request.</param> /// <param name="onRequestPermissionsResults">Callback with results.</param> public static void RequestPermissions(string[] permissions, Action <PermissionRequestResult[]> onRequestPermissionsResults) { if (permissions == null || permissions.Length == 0) { throw new ArgumentException("Requested permissions array must not be null or empty", "permissions"); } if (onRequestPermissionsResults == null) { throw new ArgumentNullException("onRequestPermissionsResults", "Listener cannot be null"); } if (AGUtils.IsNotAndroidCheck()) { return; } if (IsPriorToMarshmellow()) { return; } try { _onRequestPermissionsResults = onRequestPermissionsResults; AGActivityUtils.RequestPermissions(permissions); } catch (Exception ex) { if (Debug.isDebugBuild) { Debug.LogWarning("Could not request runtime permissions. " + ex.Message); } } }
/// <summary> /// Take the video file using the device camera /// </summary> /// <param name="onSuccess">Video file was successfully picked by the user. Result is received in a callback.</param> /// <param name="onError">Picking video file failed.</param> public static void RecordVideo(Action <VideoPickResult> onSuccess, Action <string> onError, bool generatePreviewImages = true) { if (AGUtils.IsNotAndroidCheck()) { return; } Check.Argument.IsNotNull(onSuccess, "onSuccess"); Check.Argument.IsNotNull(onError, "onError"); _onVideoSuccessAction = onSuccess; _onVideoCancelAction = onError; AGActivityUtils.PickVideoCamera(generatePreviewImages); }
/// <summary> /// Pick the audio file from the file system /// </summary> /// <param name="onSuccess">Audio file was successfully picked by the user. Result is received in a callback.</param> /// <param name="onError">Picking audio file failed.</param> public static void PickAudio(Action <AudioPickResult> onSuccess, Action <string> onError) { if (AGUtils.IsNotAndroid()) { return; } Check.Argument.IsNotNull(onSuccess, "onSuccess"); Check.Argument.IsNotNull(onError, "onError"); _onAudioSuccessAction = onSuccess; _onAudioCancelAction = onError; AGActivityUtils.PickAudio(); }
/// <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.IsNotAndroidCheck()) { return; } Check.Argument.IsNotNull(onSuccess, "onSuccess"); Check.Argument.IsNotNull(onError, "onError"); _onSuccessAction = onSuccess; _onCancelAction = onError; AGActivityUtils.PickContact(); }
public static void PickFile(Action <FilePickerResult> onSuccess, Action <string> onError, string mimeType) { if (AGUtils.IsNotAndroid()) { return; } Check.Argument.IsNotNull(onSuccess, "onSuccess"); Check.Argument.IsNotNull(onError, "onError"); _onFileSuccessAction = onSuccess; _onFileCancelAction = onError; AGActivityUtils.PickFile(mimeType); }
/// <summary> /// Picks the image from gallery. /// </summary> /// <param name="onSuccess">On success callback. Image is received as callback parameter</param> /// <param name="onError">On error callback.</param> /// <param name="maxSize">Max image size. If provided image will be downscaled.</param> /// <param name="shouldGenerateThumbnails">Whether thumbnail images will be generated. Used to show small previews of image.</param> public static void PickImageFromGallery(Action <ImagePickResult> onSuccess, Action <string> onError, ImageResultSize maxSize = ImageResultSize.Original, bool shouldGenerateThumbnails = true) { if (AGUtils.IsNotAndroidCheck()) { return; } Check.Argument.IsNotNull(onSuccess, "onSuccess"); _onSuccessAction = onSuccess; _onCancelAction = onError; AGActivityUtils.PickPhotoFromGallery(maxSize, shouldGenerateThumbnails); }
/// <summary> /// Takes the small photo. This thumbnail image might be good for an icon, but not a lot more. /// </summary> /// <param name="onSuccess">On success callback. Image is received as callback parameter</param> /// <param name="onCancel">On cancel callback.</param> public static void TakeSmallPhoto(Action <ImagePickResult> onSuccess, Action onCancel) { if (AGUtils.IsNotAndroidCheck()) { return; } if (onSuccess == null) { throw new ArgumentNullException("onSuccess", "Success callback cannot be null"); } var listener = new AGActivityUtils.OnPickPhotoListener(onSuccess, onCancel); AGUtils.RunOnUiThread(() => AGActivityUtils.TakePhotoSmall(listener)); }
/// <summary> /// Required permissions: /// <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> /// /// Launches the camera app to take a photo and returns resulting Texture2D in callback. The photo is also saved to the device gallery. /// /// IMPORTANT! : You don't need any permissions to use this method. It works using Android intent. /// </summary> /// <param name="onSuccess">On success callback. Image is received as callback parameter</param> /// <param name="onError">On error/cancel callback.</param> /// <param name="maxSize">Max image size. If provided image will be downscaled.</param> /// <param name="shouldGenerateThumbnails">Whether thumbnail images will be generated. Used to show small previews of image.</param> public static void TakePhoto(Action <ImagePickResult> onSuccess, Action <string> onError, ImageResultSize maxSize = ImageResultSize.Original, bool shouldGenerateThumbnails = true) { if (AGUtils.IsNotAndroidCheck()) { return; } if (onSuccess == null) { throw new ArgumentNullException("onSuccess", "Success callback cannot be null"); } _onSuccessAction = onSuccess; _onCancelAction = onError; AGUtils.RunOnUiThread(() => AGActivityUtils.TakePhoto(maxSize, shouldGenerateThumbnails)); }
/// <summary> /// Picks the image from gallery. /// </summary> /// <param name="onSuccess">On success callback. Image is received as callback parameter</param> /// <param name="onCancel">On cancel callback.</param> /// <param name="imageFormat">Image format.</param> /// <param name="maxSize">Max image size. If provided image will be downscaled.</param> public static void PickImageFromGallery(Action <ImagePickResult> onSuccess, Action onCancel, ImageFormat imageFormat = ImageFormat.PNG, ImageResultSize maxSize = ImageResultSize.Original) { if (AGUtils.IsNotAndroidCheck()) { return; } if (onSuccess == null) { throw new ArgumentNullException("onSuccess", "Success callback cannot be null"); } AGUtils.RunOnUiThread( () => AGActivityUtils.PickPhotoFromGallery( new AGActivityUtils.OnPickPhotoListener(onSuccess, onCancel), imageFormat, maxSize)); }
/// <summary> /// Required permissions: /// <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> /// /// Launches the camera app to take a photo and returns resulting Texture2D in callback. The photo is also saved to the device gallery. /// /// IMPORTANT! : You don't need any permissions to use this method. It works using Android intent. /// </summary> /// <param name="onSuccess">On success callback. Image is received as callback parameter</param> /// <param name="onCancel">On cancel callback.</param> /// <param name="maxSize">Max image size. If provided image will be downscaled.</param> /// <param name="albumName">Album where photo will be stored.</param> public static void TakePhoto(Action <ImagePickResult> onSuccess, Action onCancel, ImageResultSize maxSize = ImageResultSize.Original, string albumName = DefaultAlbumName) { if (AGUtils.IsNotAndroidCheck()) { return; } if (onSuccess == null) { throw new ArgumentNullException("onSuccess", "Success callback cannot be null"); } var listener = new AGActivityUtils.OnPickPhotoListener(onSuccess, onCancel); AGUtils.RunOnUiThread(() => AGActivityUtils.TakePhotoBig(listener, maxSize, albumName)); }
/// <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(); }
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); }
/// <summary> /// Requests the required runtime permissions for your application. /// </summary> /// <param name="permissions">Permissions to request.</param> /// <param name="onRequestPermissionsResults">Callback with results.</param> public static void RequestPermissions(string[] permissions, Action <PermissionRequestResult[]> onRequestPermissionsResults) { if (permissions == null || permissions.Length == 0) { throw new ArgumentException("Requested permissions array must not be null or empty", "permissions"); } if (onRequestPermissionsResults == null) { throw new ArgumentNullException("onRequestPermissionsResults", "Listener cannot be null"); } if (AGUtils.IsNotAndroidCheck()) { return; } if (IsPriorToMarshmellow()) { return; } try { var listener = new OnRequestPermissionsResultsListener(onRequestPermissionsResults); AGUtils.RunOnUiThread(() => { AGActivityUtils.AndroidGoodiesActivityClass.CallStatic("prepareToRequestPermissions", listener, permissions); AGActivityUtils.StartAndroidGoodiesActivity(); }); } catch (Exception ex) { if (Debug.isDebugBuild) { Debug.LogWarning("Could not request runtime permissions. " + ex.Message); } } }