Skip to content

Commit

Permalink
No permission will be asked in Android 14+ devices because partial me…
Browse files Browse the repository at this point in the history
…dia access permissions are confusing for the end-user
  • Loading branch information
yasirkula committed Jul 11, 2023
1 parent 7203cbe commit 1283f87
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class NativeGallery

public static boolean overwriteExistingMedia = false;
public static boolean mediaSaveOmitDCIM = false; // If set to true, 'directoryName' on Android 29+ must start with either "DCIM/" or ["Pictures/", "Movies/", "Music/", "Alarms/", "Notifications/", "Audiobooks/", "Podcasts/", "Ringtones/"]
public static boolean PermissionFreeMode = false; // true: Permissions for reading/writing media elements won't be requested

public static String SaveMedia( Context context, int mediaType, String filePath, String directoryName )
{
Expand Down Expand Up @@ -341,6 +342,9 @@ public static int CheckPermission( Context context, final boolean readPermission
if( Build.VERSION.SDK_INT < Build.VERSION_CODES.M )
return 1;

if( PermissionFreeMode )
return 1;

if( !readPermission )
{
if( android.os.Build.VERSION.SDK_INT >= 29 ) // On Android 10 and later, saving to Gallery doesn't require any permissions
Expand All @@ -354,8 +358,13 @@ else if( context.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE
if( context.checkSelfPermission( Manifest.permission.READ_EXTERNAL_STORAGE ) != PackageManager.PERMISSION_GRANTED )
return 0;
}
else
else if( Build.VERSION.SDK_INT < 34 )
{
// On Android 14+ (34), partial media access permission is introduced which we want to avoid because they're
// confusing for the end user and media access permission shouldn't have been necessary in the first place for
// the Intents we're using. They were there to avoid edge cases in some problematic devices:
// https://developer.android.com/about/versions/14/changes/partial-photo-video-access
// We're hoping that by now, those problematic devices have resolved their issues.
if( ( mediaType & MEDIA_TYPE_IMAGE ) == MEDIA_TYPE_IMAGE && context.checkSelfPermission( "android.permission.READ_MEDIA_IMAGES" ) != PackageManager.PERMISSION_GRANTED )
return 0;
if( ( mediaType & MEDIA_TYPE_VIDEO ) == MEDIA_TYPE_VIDEO && context.checkSelfPermission( "android.permission.READ_MEDIA_VIDEO" ) != PackageManager.PERMISSION_GRANTED )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void onCreate( Bundle savedInstanceState )
requestPermissions( new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE }, PERMISSIONS_REQUEST_CODE );
else if( Build.VERSION.SDK_INT < 33 || getActivity().getApplicationInfo().targetSdkVersion < 33 )
requestPermissions( new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, PERMISSIONS_REQUEST_CODE );
else
else if( Build.VERSION.SDK_INT < 34 )
{
ArrayList<String> permissions = new ArrayList<String>( 3 );
int mediaType = getArguments().getInt( MEDIA_TYPE_ID );
Expand All @@ -80,6 +80,8 @@ else if( Build.VERSION.SDK_INT < 33 || getActivity().getApplicationInfo().target

requestPermissions( permissionsArray, PERMISSIONS_REQUEST_CODE );
}
else
onRequestPermissionsResult( PERMISSIONS_REQUEST_CODE, new String[0], new int[0] );
}
}

Expand Down
2 changes: 1 addition & 1 deletion .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Almost all of these functions return a *NativeGallery.Permission* value. More de

### C. Runtime Permissions

Beginning with *6.0 Marshmallow*, Android apps must request runtime permissions before accessing certain services, similar to iOS. Note that NativeGallery doesn't require any permissions for picking images/videos from Photos on iOS 11+ and saving images/videos to Gallery on Android 29+, so no permission dialog will be shown in these cases and the permission functions will return *Permission.Granted*.
Beginning with *6.0 Marshmallow*, Android apps must request runtime permissions before accessing certain services, similar to iOS. Note that NativeGallery doesn't require any permissions for picking images/videos from Photos on iOS 11+, picking images/videos from Gallery on Android 34+ and saving images/videos to Gallery on Android 29+, so no permission dialog will be shown in these cases and the permission functions will return *Permission.Granted*.

There are two functions to handle permissions with this plugin:

Expand Down
Binary file modified Plugins/NativeGallery/Android/NativeGallery.aar
Binary file not shown.
2 changes: 1 addition & 1 deletion Plugins/NativeGallery/README.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= Native Gallery for Android & iOS (v1.7.2) =
= Native Gallery for Android & iOS (v1.7.3) =

Online documentation & example code available at: https://github.com/yasirkula/UnityNativeGallery
E-mail: [email protected]
Expand Down
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.nativegallery",
"displayName": "Native Gallery",
"version": "1.7.2",
"version": "1.7.3",
"documentationUrl": "https://github.com/yasirkula/UnityNativeGallery",
"changelogUrl": "https://github.com/yasirkula/UnityNativeGallery/releases",
"licensesUrl": "https://github.com/yasirkula/UnityNativeGallery/blob/master/LICENSE.txt",
Expand Down

0 comments on commit 1283f87

Please sign in to comment.