Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

Commit 178bc41

Browse files
phcannessonsamtstern
authored andcommitted
Fixed crash on rationale click listener when using android.app.Fragment (#78)
1 parent 390cbf5 commit 178bc41

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

easypermissions/src/main/java/pub/devrel/easypermissions/RationaleDialogClickListener.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,15 @@ public void onClick(DialogInterface dialog, int which) {
5353
if (which == Dialog.BUTTON_POSITIVE) {
5454
if (mHost instanceof Fragment) {
5555
((Fragment) mHost).requestPermissions(mConfig.permissions, mConfig.requestCode);
56-
} else { // mHost instance of FragmentActivity
56+
} else if (mHost instanceof android.app.Fragment) {
57+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
58+
((android.app.Fragment) mHost)
59+
.requestPermissions(mConfig.permissions, mConfig.requestCode);
60+
} else {
61+
throw new IllegalArgumentException(
62+
"Target SDK needs to be greater than 23 if caller is android.app.Fragment");
63+
}
64+
} else if (mHost instanceof FragmentActivity) {
5765
ActivityCompat.requestPermissions(
5866
(FragmentActivity) mHost, mConfig.permissions, mConfig.requestCode);
5967
}

0 commit comments

Comments
 (0)