Skip to content

Commit

Permalink
Potential fix for IllegalStateException on Android (closed #15)
Browse files Browse the repository at this point in the history
  • Loading branch information
yasirkula committed Nov 14, 2023
1 parent 2113d0b commit 052f4e1
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static void RequestPermission( final String[] permissions, final Context
final Fragment request = new RuntimePermissionsFragment( permissionReceiver );
request.setArguments( bundle );

( (Activity) context ).getFragmentManager().beginTransaction().add( 0, request ).commit();
( (Activity) context ).getFragmentManager().beginTransaction().add( 0, request ).commitAllowingStateLoss();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import android.util.Log;

import java.util.ArrayList;
import java.util.Random;

/**
* Created by yasirkula on 27.04.2018.
Expand Down Expand Up @@ -40,7 +39,7 @@ public void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
if( permissionReceiver == null )
getFragmentManager().beginTransaction().remove( this ).commit();
onRequestPermissionsResult( PERMISSIONS_REQUEST_CODE, new String[0], new int[0] );
else
{
m_permissions = getArguments().getStringArray( PERMISSIONS );
Expand All @@ -59,7 +58,7 @@ public void onRequestPermissionsResult( int requestCode, String[] permissions, i
{
Log.e( "Unity", "Fragment data got reset while asking permissions!" );

getFragmentManager().beginTransaction().remove( this ).commit();
getFragmentManager().beginTransaction().remove( this ).commitAllowingStateLoss();
return;
}

Expand Down Expand Up @@ -113,7 +112,7 @@ else if( !shouldShowRequestPermissionRationale( permission ) ) // This can cause
result += permissionsResult.get( i );

permissionReceiver.OnPermissionResult( result );
getFragmentManager().beginTransaction().remove( this ).commit();
getFragmentManager().beginTransaction().remove( this ).commitAllowingStateLoss();

// Resolves a bug in Unity 2019 where the calling activity
// doesn't resume automatically after the fragment finishes
Expand Down
Binary file modified Plugins/AndroidRuntimePermissions/Android/RuntimePermissions.aar
Binary file not shown.
30 changes: 4 additions & 26 deletions Plugins/AndroidRuntimePermissions/README.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
= Android Runtime Permissions (v1.2.0) =
= Android Runtime Permissions (v1.2.1) =

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

1. ABOUT
This plugin helps you query/request runtime permissions on Android M and later.

2. HOW TO
You can use the following static functions of AndroidRuntimePermissions to manage runtime permissions:

- bool CheckPermission( string permission ): checks whether or not the permission is granted

- bool[] CheckPermissions( params string[] permissions ): queries multiple permissions simultaneously. The returned array will contain one entry per queried permission

- Permission RequestPermission( string permission ): requests a permission 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". Permission is an enum that can take 3 values:
-- Granted: permission is granted
-- ShouldAsk: permission is denied but we can ask the user for permission once again. As long as the user doesn't select "Don't ask again" while denying the permission, ShouldAsk is returned
-- 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 app's Settings. This happens when user selects "Don't ask again" while denying the permission or when user is not allowed to give that permission (parental controls etc.)

- Permission[] RequestPermissions( params string[] permissions ): requests multiple permissions simultaneously

- Task<Permission> RequestPermissionAsync( string permission ): asynchronous version of RequestPermission. Unlike RequestPermission, this function doesn't freeze the app unnecessarily before the permission dialog is displayed

- Task<Permission[]> RequestPermissionsAsync( string[] permissions ): asynchronous version of RequestPermissions

- void OpenSettings(): opens the settings for this app, from where the user can manually grant permission(s) in case a needed permission's state is Permission.Denied
Documentation: https://github.com/yasirkula/UnityAndroidRuntimePermissions
Example code: https://github.com/yasirkula/UnityAndroidRuntimePermissions#example-code
E-mail: yasirkula@gmail.com
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.androidruntimepermissions",
"displayName": "Android Runtime Permissions",
"version": "1.2.0",
"version": "1.2.1",
"documentationUrl": "https://github.com/yasirkula/UnityAndroidRuntimePermissions",
"changelogUrl": "https://github.com/yasirkula/UnityAndroidRuntimePermissions/releases",
"licensesUrl": "https://github.com/yasirkula/UnityAndroidRuntimePermissions/blob/master/LICENSE.txt",
Expand Down

0 comments on commit 052f4e1

Please sign in to comment.