Skip to content

Commit 9c6272a

Browse files
committed
No media permission will be asked on Android 14+ devices because partial media access permissions are confusing for the end-user + Fixed RequestPermission sometimes not working when the permission was reset via Settings
1 parent acfd94f commit 9c6272a

File tree

6 files changed

+19
-23
lines changed

6 files changed

+19
-23
lines changed

.github/AAR Source (Android)/java/com/yasirkula/unity/NativeCamera.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,16 @@ public static int CheckPermission( Context context, final boolean isPicturePermi
9191
if( context.checkSelfPermission( Manifest.permission.READ_EXTERNAL_STORAGE ) != PackageManager.PERMISSION_GRANTED )
9292
return 0;
9393
}
94-
else if( isPicturePermission )
94+
else if( Build.VERSION.SDK_INT < 34 && context.checkSelfPermission( isPicturePermission ? "android.permission.READ_MEDIA_IMAGES" : "android.permission.READ_MEDIA_VIDEO" ) != PackageManager.PERMISSION_GRANTED )
9595
{
96-
if( context.checkSelfPermission( "android.permission.READ_MEDIA_IMAGES" ) != PackageManager.PERMISSION_GRANTED )
97-
return 0;
98-
}
99-
else
100-
{
101-
if( context.checkSelfPermission( "android.permission.READ_MEDIA_VIDEO" ) != PackageManager.PERMISSION_GRANTED )
102-
return 0;
96+
// 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):
97+
// https://developer.android.com/about/versions/14/changes/partial-photo-video-access
98+
// We're hoping that by now, the native camera apps have become smart enough to avoid saving the captured media to Gallery.
99+
return 0;
103100
}
104101
}
105102

106-
// Credit: https://blog.egorand.me/taking-photos-not-so-simply-how-i-got-bitten-by-action_image_capture/
103+
// If CAMERA permission is declared, we must request it: https://developer.android.com/reference/android/provider/MediaStore#ACTION_IMAGE_CAPTURE
107104
if( NativeCameraUtils.IsPermissionDefinedInManifest( context, Manifest.permission.CAMERA ) && context.checkSelfPermission( Manifest.permission.CAMERA ) != PackageManager.PERMISSION_GRANTED )
108105
return 0;
109106

.github/AAR Source (Android)/java/com/yasirkula/unity/NativeCameraPermissionFragment.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,18 @@ public void onCreate( Bundle savedInstanceState )
6767

6868
if( Build.VERSION.SDK_INT < 33 || getActivity().getApplicationInfo().targetSdkVersion < 33 )
6969
permissions.add( Manifest.permission.READ_EXTERNAL_STORAGE );
70-
else
71-
{
72-
boolean isPicturePermission = getArguments().getBoolean( PICTURE_PERMISSION_ID );
73-
if( isPicturePermission )
74-
permissions.add( "android.permission.READ_MEDIA_IMAGES" );
75-
else
76-
permissions.add( "android.permission.READ_MEDIA_VIDEO" );
77-
}
70+
else if( Build.VERSION.SDK_INT < 34 )
71+
permissions.add( getArguments().getBoolean( PICTURE_PERMISSION_ID ) ? "android.permission.READ_MEDIA_IMAGES" : "android.permission.READ_MEDIA_VIDEO" );
7872

79-
String[] permissionsArray = new String[permissions.size()];
80-
permissions.toArray( permissionsArray );
73+
if( permissions.size() > 0 )
74+
{
75+
String[] permissionsArray = new String[permissions.size()];
76+
permissions.toArray( permissionsArray );
8177

82-
requestPermissions( permissionsArray, PERMISSIONS_REQUEST_CODE );
78+
requestPermissions( permissionsArray, PERMISSIONS_REQUEST_CODE );
79+
}
80+
else
81+
onRequestPermissionsResult( PERMISSIONS_REQUEST_CODE, new String[0], new int[0] );
8382
}
8483
}
8584

39 Bytes
Binary file not shown.

Plugins/NativeCamera/NativeCamera.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public static Permission RequestPermission( bool isPicturePermission )
179179
{
180180
NCPermissionCallbackAndroid nativeCallback = new NCPermissionCallbackAndroid( threadLock );
181181

182-
AJC.CallStatic( "RequestPermission", Context, nativeCallback, isPicturePermission, PlayerPrefs.GetInt( "NativeCameraPermission", (int) Permission.ShouldAsk ) );
182+
AJC.CallStatic( "RequestPermission", Context, nativeCallback, isPicturePermission, (int) Permission.ShouldAsk );
183183

184184
if( nativeCallback.Result == -1 )
185185
System.Threading.Monitor.Wait( threadLock );

Plugins/NativeCamera/README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
= Native Camera for Android & iOS (v1.3.8) =
1+
= Native Camera for Android & iOS (v1.3.9) =
22

33
Online documentation & example code available at: https://github.com/yasirkula/UnityNativeCamera
44
E-mail: yasirkula@gmail.com

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.yasirkula.nativecamera",
33
"displayName": "Native Camera",
4-
"version": "1.3.8",
4+
"version": "1.3.9",
55
"documentationUrl": "https://github.com/yasirkula/UnityNativeCamera",
66
"changelogUrl": "https://github.com/yasirkula/UnityNativeCamera/releases",
77
"licensesUrl": "https://github.com/yasirkula/UnityNativeCamera/blob/master/LICENSE.txt",

0 commit comments

Comments
 (0)