Skip to content

Commit

Permalink
Bugfix for Denied permission on Android 11 and later
Browse files Browse the repository at this point in the history
  • Loading branch information
yasirkula committed Apr 25, 2022
1 parent 5f57882 commit 72fca3d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ public static int CheckPermission( Context context )
if( Build.VERSION.SDK_INT < Build.VERSION_CODES.M )
return 1;

if( context.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE ) != PackageManager.PERMISSION_GRANTED ||
context.checkSelfPermission( Manifest.permission.READ_EXTERNAL_STORAGE ) != PackageManager.PERMISSION_GRANTED )
if( context.checkSelfPermission( Manifest.permission.READ_EXTERNAL_STORAGE ) != PackageManager.PERMISSION_GRANTED )
return 0;

if( Build.VERSION.SDK_INT < 30 && context.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE ) != PackageManager.PERMISSION_GRANTED )
return 0;

// Credit: https://blog.egorand.me/taking-photos-not-so-simply-how-i-got-bitten-by-action_image_capture/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,19 @@ public void onCreate( Bundle savedInstanceState )
{
String[] permissions;
if( NativeCameraUtils.IsPermissionDefinedInManifest( getActivity(), Manifest.permission.CAMERA ) )
permissions = new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA };
{
if( Build.VERSION.SDK_INT < 30 )
permissions = new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA };
else
permissions = new String[] { Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA };
}
else
permissions = new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE };
{
if( Build.VERSION.SDK_INT < 30 )
permissions = new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE };
else
permissions = new String[] { Manifest.permission.READ_EXTERNAL_STORAGE };
}

requestPermissions( permissions, PERMISSIONS_REQUEST_CODE );
}
Expand Down
Binary file modified Plugins/NativeCamera/Android/NativeCamera.aar
Binary file not shown.
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.3.2",
"version": "1.3.3",
"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 72fca3d

Please sign in to comment.