Skip to content

Commit

Permalink
Removed the new READ_MEDIA permissions: https://support.google.com/go…
Browse files Browse the repository at this point in the history
  • Loading branch information
yasirkula committed Oct 28, 2023
1 parent 8137d3e commit 0f1c4bf
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 115 deletions.
2 changes: 0 additions & 2 deletions .github/AAR Source (Android)/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@
<uses-feature android:name="android.hardware.camera.front" android:required="false" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" tools:node="replace" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="replace" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" tools:node="replace" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" tools:node="replace" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,6 @@ public static int CheckPermission( Context context, final boolean isPicturePermi
if( context.checkSelfPermission( Manifest.permission.READ_EXTERNAL_STORAGE ) != PackageManager.PERMISSION_GRANTED )
return 0;
}
else if( Build.VERSION.SDK_INT < 34 && context.checkSelfPermission( isPicturePermission ? "android.permission.READ_MEDIA_IMAGES" : "android.permission.READ_MEDIA_VIDEO" ) != PackageManager.PERMISSION_GRANTED )
{
// On Android 14+ (34), partial media access permission is introduced which we want to avoid in a camera app (it'd be confusing for the end user):
// https://developer.android.com/about/versions/14/changes/partial-photo-video-access
// We're hoping that by now, the native camera apps have become smart enough to avoid saving the captured media to Gallery.
return 0;
}
}

// If CAMERA permission is declared, we must request it: https://developer.android.com/reference/android/provider/MediaStore#ACTION_IMAGE_CAPTURE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ public void onCreate( Bundle savedInstanceState )

if( Build.VERSION.SDK_INT < 33 || getActivity().getApplicationInfo().targetSdkVersion < 33 )
permissions.add( Manifest.permission.READ_EXTERNAL_STORAGE );
else if( Build.VERSION.SDK_INT < 34 )
permissions.add( getArguments().getBoolean( PICTURE_PERMISSION_ID ) ? "android.permission.READ_MEDIA_IMAGES" : "android.permission.READ_MEDIA_VIDEO" );

if( permissions.size() > 0 )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,13 @@ public static String GetVideoProperties( Context context, final String path )
}
finally
{
metadataRetriever.release();
try
{
metadataRetriever.release();
}
catch( Exception e )
{
}
}
}

Expand Down Expand Up @@ -824,7 +830,13 @@ public static String GetVideoThumbnail( Context context, final String path, fina
}
finally
{
metadataRetriever.release();
try
{
metadataRetriever.release();
}
catch( Exception e )
{
}
}
}

Expand Down
Binary file modified Plugins/NativeCamera/Android/NativeCamera.aar
Binary file not shown.
106 changes: 5 additions & 101 deletions Plugins/NativeCamera/README.txt
Original file line number Diff line number Diff line change
@@ -1,102 +1,6 @@
= Native Camera for Android & iOS (v1.4.0) =
= Native Camera for Android & iOS (v1.4.1) =

Online documentation & example code available at: https://github.com/yasirkula/UnityNativeCamera
E-mail: [email protected]


1. ABOUT
This plugin helps you take pictures/record videos natively with your device's camera on Android & iOS.


2. HOW TO
NativeCamera no longer requires any manual setup on Android. If you were using an older version of the plugin, you need to remove NativeCamera's "<provider ... />" from your AndroidManifest.xml.

For reference, the legacy documentation is available at: https://github.com/yasirkula/UnityNativeCamera/wiki/Manual-Setup-for-Android

2.2. iOS Setup
There are two ways to set up the plugin on iOS:

2.2.a. Automated Setup for iOS
- (optional) change the values of 'Camera Usage Description' and 'Microphone Usage Description' at 'Project Settings/yasirkula/Native Camera'

2.2.b. Manual Setup for iOS
- set the value of 'Automated Setup' to false at 'Project Settings/yasirkula/Native Camera'
- build your project
- enter a Camera Usage Description to Info.plist in Xcode
- insert "-framework MobileCoreServices -framework ImageIO" to the "Other Linker Flags" of Unity-iPhone Target (and UnityFramework Target on Unity 2019.3 or newer)


3. FAQ
- Can't use the camera, it says "java.lang.ClassNotFoundException: com.yasirkula.unity.NativeCamera" in Logcat
If you are sure that your plugin is up-to-date, then enable "Custom Proguard File" option from Player Settings and add the following line to that file: -keep class com.yasirkula.unity.* { *; }


4. SCRIPTING API
Please see the online documentation for a more in-depth documentation of the Scripting API: https://github.com/yasirkula/UnityNativeCamera

enum NativeCamera.Permission { Denied = 0, Granted = 1, ShouldAsk = 2 };
enum NativeCamera.Quality { Default = -1, Low = 0, Medium = 1, High = 2 };
enum NativeCamera.ImageOrientation { Unknown = -1, Normal = 0, Rotate90 = 1, Rotate180 = 2, Rotate270 = 3, FlipHorizontal = 4, Transpose = 5, FlipVertical = 6, Transverse = 7 }; // EXIF orientation: http://sylvana.net/jpegcrop/exif_orientation.html (indices are reordered)

delegate void PermissionCallback( NativeCamera.Permission permission );
delegate void CameraCallback( string path );

//// Accessing Camera ////

// This operation is asynchronous! After user takes a picture or cancels the operation, the callback is called (on main thread)
// CameraCallback takes a string parameter which stores the path of the captured image, or null if the operation is canceled
// maxSize: determines the maximum size of the returned image in pixels on iOS. A larger image will be down-scaled for better performance. If untouched, its value will be set to SystemInfo.maxTextureSize. Has no effect on Android
// saveAsJPEG: determines whether the image is saved as JPEG or PNG. Has no effect on Android
// preferredCamera: determines whether the rear camera or the front camera should be opened by default
NativeCamera.Permission NativeCamera.TakePicture( CameraCallback callback, int maxSize = -1, bool saveAsJPEG = true, PreferredCamera preferredCamera = PreferredCamera.Default );

// quality: determines the quality of the recorded video
// maxDuration: determines the maximum duration, in seconds, for the recorded video. If untouched, there will be no limit. Please note that the functionality of this parameter depends on whether the device vendor has added this capability to the camera or not. So, this parameter may not have any effect on some devices
// maxSizeBytes: determines the maximum size, in bytes, for the recorded video. If untouched, there will be no limit. This parameter has no effect on iOS. Please note that the functionality of this parameter depends on whether the device vendor has added this capability to the camera or not. So, this parameter may not have any effect on some devices
NativeCamera.Permission NativeCamera.RecordVideo( CameraCallback callback, Quality quality = Quality.Default, int maxDuration = 0, long maxSizeBytes = 0L, PreferredCamera preferredCamera = PreferredCamera.Default );

bool NativeCamera.DeviceHasCamera(); // returns false if the device doesn't have a camera. In this case, TakePicture and RecordVideo functions will not execute

bool NativeCamera.IsCameraBusy(); // returns true if the camera is currently open. In that case, another TakePicture or RecordVideo request will simply be ignored


//// Runtime Permissions ////

// Accessing camera is only possible when permission state is Permission.Granted. TakePicture and RecordVideo functions request permission internally (and return the result) but you can also check/request the permissions manually
// isPicturePermission: whether we're checking permission to take a picture or record a video. Has no effect on iOS
NativeCamera.Permission NativeCamera.CheckPermission( bool isPicturePermission );
NativeCamera.Permission NativeCamera.RequestPermission( bool isPicturePermission );

// Asynchronous variants of RequestPermission. Unlike RequestPermission, these functions don't freeze the app unnecessarily before the permission dialog is displayed. So it's recommended to call these functions instead
void NativeCamera.RequestPermissionAsync( PermissionCallback callback, PermissionType permissionType, MediaType mediaTypes );
Task<NativeCamera.Permission> NativeCamera.RequestPermissionAsync( PermissionType permissionType, MediaType mediaTypes );

// If permission state is Permission.Denied, user must grant the necessary permission(s) manually from the Settings (Android requires Storage and, if declared in AndroidManifest, Camera permissions; iOS requires Camera permission). These functions help you open the Settings directly from within the app
void NativeCamera.OpenSettings();
bool NativeCamera.CanOpenSettings();


//// Utility Functions ////

// Creates a Texture2D from the specified image file in correct orientation and returns it. Returns null, if something goes wrong
// maxSize: determines the maximum size of the returned Texture2D in pixels. Larger textures 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
// markTextureNonReadable: marks the generated texture as non-readable for better memory usage. If you plan to modify the texture later (e.g. GetPixels/SetPixels), set its value to false
// generateMipmaps: determines whether texture should have mipmaps or not
// linearColorSpace: determines whether texture should be in linear color space or sRGB color space
Texture2D NativeCamera.LoadImageAtPath( string imagePath, int maxSize = -1, bool markTextureNonReadable = true, bool generateMipmaps = true, bool linearColorSpace = false );
async Task<Texture2D> NativeCamera.LoadImageAtPathAsync( string imagePath, int maxSize = -1, 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
// 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
// captureTimeInSeconds: determines the frame of the video that the thumbnail is captured from. If untouched, OS will decide this value
// markTextureNonReadable: see LoadImageAtPath
// generateMipmaps: see LoadImageAtPath
// linearColorSpace: see LoadImageAtPath
Texture2D NativeCamera.GetVideoThumbnail( string videoPath, int maxSize = -1, double captureTimeInSeconds = -1.0, bool markTextureNonReadable = true, bool generateMipmaps = true, bool linearColorSpace = false );
async Task<Texture2D> NativeCamera.GetVideoThumbnailAsync( string videoPath, int maxSize = -1, double captureTimeInSeconds = -1.0, bool markTextureNonReadable = true, bool generateMipmaps = true, bool linearColorSpace = false );

// Returns an ImageProperties instance that holds the width, height and mime type information of an image file without creating a Texture2D object. Mime type will be null, if it can't be determined
NativeCamera.ImageProperties NativeCamera.GetImageProperties( string imagePath );

// Returns a VideoProperties instance that holds the width, height, duration (in milliseconds) and rotation information of a video file. To play a video in correct orientation, you should rotate it by rotation degrees clockwise. For a 90-degree or 270-degree rotated video, values of width and height should be swapped to get the display size of the video
NativeCamera.VideoProperties NativeCamera.GetVideoProperties( string videoPath );
Documentation: https://github.com/yasirkula/UnityNativeCamera
FAQ: https://github.com/yasirkula/UnityNativeCamera#faq
Example code: https://github.com/yasirkula/UnityNativeCamera#example-code
E-mail: [email protected]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.yasirkula.nativecamera",
"displayName": "Native Camera",
"version": "1.4.0",
"version": "1.4.1",
"documentationUrl": "https://github.com/yasirkula/UnityNativeCamera",
"changelogUrl": "https://github.com/yasirkula/UnityNativeCamera/releases",
"licensesUrl": "https://github.com/yasirkula/UnityNativeCamera/blob/master/LICENSE.txt",
Expand Down

0 comments on commit 0f1c4bf

Please sign in to comment.