diff --git a/granter/src/main/java/se/eelde/granter/GranterFragment.java b/granter/src/main/java/se/eelde/granter/GranterFragment.java index 4c3bd4b..24a67d4 100644 --- a/granter/src/main/java/se/eelde/granter/GranterFragment.java +++ b/granter/src/main/java/se/eelde/granter/GranterFragment.java @@ -1,15 +1,12 @@ package se.eelde.granter; -import android.content.Context; import android.content.Intent; -import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import androidx.annotation.NonNull; @@ -18,6 +15,7 @@ import pub.devrel.easypermissions.AfterPermissionGranted; import pub.devrel.easypermissions.AppSettingsDialog; import pub.devrel.easypermissions.EasyPermissions; +import pub.devrel.easypermissions.PermissionRequest; public class GranterFragment extends Fragment implements EasyPermissions.PermissionCallbacks { @@ -47,10 +45,6 @@ static GranterFragment newInstance(@NonNull ArrayList permissions, int r @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Context context = getContext(); - if (context == null) { - throw new IllegalStateException("Context cannot be null"); - } Bundle arguments = getArguments(); if (arguments == null) { throw new IllegalStateException("Arguments cannot be null"); @@ -67,16 +61,8 @@ public void onCreate(@Nullable Bundle savedInstanceState) { shouldHaveShownRationale = Stolen.shouldShowRationale(this, requestedPermissions); if (savedInstanceState == null) { - if (!EasyPermissions.hasPermissions(getContext(), requestedPermissions)) { - EasyPermissions.requestPermissions(this, - rationale, - RC_PERMISSIONS, - requestedPermissions); - } else { - int[] ints = new int[requestedPermissions.length]; - Arrays.fill(ints, PackageManager.PERMISSION_GRANTED); - callback(requestedPermissions, ints); - } + PermissionRequest permissionRequest = new PermissionRequest.Builder(this, RC_PERMISSIONS, requestedPermissions).setRationale(rationale).build(); + EasyPermissions.requestPermissions(permissionRequest); } } diff --git a/granter/src/main/java/se/eelde/granter/Stolen.java b/granter/src/main/java/se/eelde/granter/Stolen.java index 106f2e7..045bfe5 100644 --- a/granter/src/main/java/se/eelde/granter/Stolen.java +++ b/granter/src/main/java/se/eelde/granter/Stolen.java @@ -73,7 +73,7 @@ static int[] grantsFromPermissions(@NonNull Fragment fragment, @NonNull String[] int[] grantResults = new int[requestedPermissions.length]; for (int i = 0; i < requestedPermissions.length; i++) { - grantResults[i] = EasyPermissions.hasPermissions(fragment.getContext(), requestedPermissions[i]) ? PackageManager.PERMISSION_GRANTED : PackageManager.PERMISSION_DENIED; + grantResults[i] = EasyPermissions.hasPermissions(fragment.requireContext(), requestedPermissions[i]) ? PackageManager.PERMISSION_GRANTED : PackageManager.PERMISSION_DENIED; } return grantResults;