You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- BREAKING CHANGE: Replaced RequestPermission with RequestPermissionAsync (see yasirkula/UnityNativeGallery#343)
- BREAKING CHANGE: Removed CanOpenSettings since it's now always true
- Updated Unity version to 2021.3.41f1 (simplified codebase accordingly)
- iOS frameworks are now added properly instead of changing OTHER_LDFLAGS
- Fixed Xcode compiler warnings
Copy file name to clipboardExpand all lines: .github/README.md
+12-28Lines changed: 12 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,7 +49,7 @@ If you are sure that your plugin is up-to-date, then enable **Custom Proguard Fi
49
49
50
50
-**NativeCamera functions return Permission.Denied even though I've granted the permission"**
51
51
52
-
Declare `WRITE_EXTERNAL_STORAGE` permission manually in your [**Plugins/Android/AndroidManifest.xml**file](https://answers.unity.com/questions/982710/where-is-the-manifest-file-in-unity.html)with the `tools:node="replace"` attribute as follows: `<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="replace"/>` (you'll need to add the `xmlns:tools="http://schemas.android.com/tools"` attribute to the `<manifest ...>` element).
52
+
Declare `WRITE_EXTERNAL_STORAGE` permission manually in your **Plugins/Android/AndroidManifest.xml** with the `tools:node="replace"` attribute as follows: `<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="replace"/>`.
53
53
54
54
## HOW TO
55
55
@@ -70,31 +70,27 @@ Declare `WRITE_EXTERNAL_STORAGE` permission manually in your [**Plugins/Android/
70
70
71
71
`NativeCamera.IsCameraBusy()`: returns true if the camera is currently open. In that case, another TakePicture or RecordVideo request will simply be ignored.
72
72
73
-
Note that TakePicture and RecordVideo functions return a*NativeCamera.Permission* value. More details available below.
73
+
Note that TakePicture and RecordVideo functions automatically call*NativeCamera.RequestPermissionAsync*. More details available below.
74
74
75
75
### B. Runtime Permissions
76
76
77
77
Beginning with *6.0 Marshmallow*, Android apps must request runtime permissions before accessing certain services, similar to iOS. There are two functions to handle permissions with this plugin:
78
78
79
-
`NativeCamera.Permission NativeCamera.CheckPermission( bool isPicturePermission )`: checks whether the app has access to camera or not.
79
+
`bool NativeCamera.CheckPermission( bool isPicturePermission )`: checks whether the app has access to camera or not.
80
80
-**isPicturePermission** determines whether we're checking permission to take a picture or record a video. Has no effect on iOS
81
81
82
+
`void NativeCamera.RequestPermissionAsync( PermissionCallback callback, bool isPicturePermission )`: requests permission to access the camera from the user and returns the result asynchronously. It is recommended to show a brief explanation before asking the permission so that user understands why the permission is needed and doesn't click Deny or worse, "Don't ask again". Note that TakePicture and RecordVideo functions call RequestPermissionAsync internally and execute only if the permission is granted.
**NativeCamera.Permission** is an enum that can take 3 values:
83
86
-**Granted**: we have the permission to access the camera
84
-
-**ShouldAsk**: we don't have permission yet, but we can ask the user for permission via *RequestPermission* function (see below). On Android, as long as the user doesn't select "Don't ask again" while denying the permission, ShouldAsk is returned
87
+
-**ShouldAsk**: permission is denied but we can ask the user for permission once again. On Android, as long as the user doesn't select "Don't ask again" while denying the permission, ShouldAsk is returned
85
88
-**Denied**: we don't have permission and we can't ask the user for permission. In this case, user has to give the permission from Settings. This happens when user denies the permission on iOS (can't request permission again on iOS), when user selects "Don't ask again" while denying the permission on Android or when user is not allowed to give that permission (parental controls etc.)
86
89
87
-
`NativeCamera.Permission NativeCamera.RequestPermission( bool isPicturePermission )`: requests permission to access the camera from the user and returns the result. It is recommended to show a brief explanation before asking the permission so that user understands why the permission is needed and doesn't click Deny or worse, "Don't ask again". Note that TakePicture and RecordVideo functions call RequestPermission internally and execute only if the permission is granted (the result of RequestPermission is then returned).
88
-
89
-
`void NativeCamera.RequestPermissionAsync( PermissionCallback callback, bool isPicturePermission )`: Asynchronous variant of *RequestPermission*. Unlike RequestPermission, this function doesn't freeze the app unnecessarily before the permission dialog is displayed. So it's recommended to call this function instead.
`Task<NativeCamera.Permission> NativeCamera.RequestPermissionAsync( bool isPicturePermission )`: Another asynchronous variant of *RequestPermission* (requires Unity 2018.4 or later).
90
+
`Task<NativeCamera.Permission> NativeCamera.RequestPermissionAsync( bool isPicturePermission )`: Task-based overload of *RequestPermissionAsync*.
93
91
94
92
`NativeCamera.OpenSettings()`: opens the settings for this app, from where the user can manually grant permission in case current permission state is *Permission.Denied* (Android requires *Storage* and, if declared in AndroidManifest, *Camera* permissions; iOS requires *Camera* permission).
95
93
96
-
`bool NativeCamera.CanOpenSettings()`: on iOS versions prior to 8.0, opening settings from within the app is not possible and in this case, this function returns *false*. Otherwise, it returns *true*.
97
-
98
94
### C. Utility Functions
99
95
100
96
`NativeCamera.ImageProperties NativeCamera.GetImageProperties( string imagePath )`: returns an *ImageProperties* instance that holds the width, height, mime type and EXIF orientation information of an image file without creating a *Texture2D* object. Mime type will be *null*, if it can't be determined.
@@ -107,14 +103,14 @@ Beginning with *6.0 Marshmallow*, Android apps must request runtime permissions
107
103
-**generateMipmaps** determines whether texture should have mipmaps or not
108
104
-**linearColorSpace** determines whether texture should be in linear color space or sRGB color space
109
105
110
-
`async Task<Texture2D> NativeCamera.LoadImageAtPathAsync( string imagePath, int maxSize = -1, bool markTextureNonReadable = true )`: asynchronous variant of *LoadImageAtPath* (requires Unity 2018.4 or later). Whether or not the returned Texture2D has mipmaps enabled depends on *UnityWebRequestTexture*'s implementation on the target Unity version. Note that it isn't possible to load multiple images simultaneously using this function.
106
+
`async Task<Texture2D> NativeCamera.LoadImageAtPathAsync( string imagePath, int maxSize = -1, bool markTextureNonReadable = true )`: asynchronous variant of *LoadImageAtPath*. Whether or not the returned Texture2D has mipmaps enabled depends on *UnityWebRequestTexture*'s implementation on the target Unity version. Note that it isn't possible to load multiple images simultaneously using this function.
111
107
112
108
`Texture2D NativeCamera.GetVideoThumbnail( string videoPath, int maxSize = -1, double captureTimeInSeconds = -1.0, bool markTextureNonReadable = true, bool generateMipmaps = true, bool linearColorSpace = false )`: creates a Texture2D thumbnail from a video file and returns it. Returns *null*, if something goes wrong.
113
109
-**maxSize** determines the maximum size of the returned Texture2D in pixels. Larger thumbnails will be down-scaled. If untouched, its value will be set to *SystemInfo.maxTextureSize*. It is recommended to set a proper maxSize for better performance
114
110
-**captureTimeInSeconds** determines the frame of the video that the thumbnail is captured from. If untouched, OS will decide this value
115
111
-**markTextureNonReadable** (see *LoadImageAtPath*)
116
112
117
-
`async Task<Texture2D> NativeCamera.GetVideoThumbnailAsync( string videoPath, int maxSize = -1, double captureTimeInSeconds = -1.0, bool markTextureNonReadable = true )`: asynchronous variant of *GetVideoThumbnail* (requires Unity 2018.4 or later). Whether or not the returned Texture2D has mipmaps enabled depends on *UnityWebRequestTexture*'s implementation on the target Unity version. Note that it isn't possible to generate multiple video thumbnails simultaneously using this function.
113
+
`async Task<Texture2D> NativeCamera.GetVideoThumbnailAsync( string videoPath, int maxSize = -1, double captureTimeInSeconds = -1.0, bool markTextureNonReadable = true )`: asynchronous variant of *GetVideoThumbnail*. Whether or not the returned Texture2D has mipmaps enabled depends on *UnityWebRequestTexture*'s implementation on the target Unity version. Note that it isn't possible to generate multiple video thumbnails simultaneously using this function.
118
114
119
115
## EXAMPLE CODE
120
116
@@ -146,17 +142,9 @@ void Update()
146
142
}
147
143
}
148
144
149
-
// Example code doesn't use this function but it is here for reference. It's recommended to ask for permissions manually using the
150
-
// RequestPermissionAsync methods prior to calling NativeCamera functions
0 commit comments