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

Commit 43e63a5

Browse files
authored
Put in defense for issue 278 (#290)
1 parent 2d46e44 commit 43e63a5

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

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

+20-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.os.Parcel;
88
import android.os.Parcelable;
99
import android.text.TextUtils;
10+
import android.util.Log;
1011

1112
import androidx.annotation.NonNull;
1213
import androidx.annotation.Nullable;
@@ -19,11 +20,14 @@
1920
/**
2021
* Dialog to prompt the user to go to the app's settings screen and enable permissions. If the user
2122
* clicks 'OK' on the dialog, they are sent to the settings screen. The result is returned to the
22-
* Activity via {@link Activity#onActivityResult(int, int, Intent)}.
23+
* Activity via {@see Activity#onActivityResult(int, int, Intent)}.
2324
* <p>
2425
* Use the {@link Builder} to create and display a dialog.
2526
*/
2627
public class AppSettingsDialog implements Parcelable {
28+
29+
private static final String TAG = "EasyPermissions";
30+
2731
public static final int DEFAULT_SETTINGS_REQ_CODE = 16061;
2832

2933
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@@ -83,6 +87,19 @@ private AppSettingsDialog(@NonNull final Object activityOrFragment,
8387

8488
static AppSettingsDialog fromIntent(Intent intent, Activity activity) {
8589
AppSettingsDialog dialog = intent.getParcelableExtra(AppSettingsDialog.EXTRA_APP_SETTINGS);
90+
91+
// It's not clear how this could happen, but in the case that it does we should try
92+
// to avoid a runtime crash and just use the default dialog.
93+
// https://github.com/googlesamples/easypermissions/issues/278
94+
if (dialog == null) {
95+
Log.e(TAG, "Intent contains null value for EXTRA_APP_SETTINGS: "
96+
+ "intent=" + intent
97+
+ ", "
98+
+ "extras=" + intent.getExtras());
99+
100+
dialog = new AppSettingsDialog.Builder(activity).build();
101+
}
102+
86103
dialog.setActivityOrFragment(activity);
87104
return dialog;
88105
}
@@ -261,7 +278,7 @@ public Builder setPositiveButton(@StringRes int textId) {
261278
* Set the negative button text, default is {@link android.R.string#cancel}.
262279
* <p>
263280
* To know if a user cancelled the request, check if your permissions were given with {@link
264-
* EasyPermissions#hasPermissions(Context, String...)} in {@link
281+
* EasyPermissions#hasPermissions(Context, String...)} in {@see
265282
* Activity#onActivityResult(int, int, Intent)}. If you still don't have the right
266283
* permissions, then the request was cancelled.
267284
*/
@@ -282,7 +299,7 @@ public Builder setNegativeButton(@StringRes int textId) {
282299

283300
/**
284301
* Set the request code use when launching the Settings screen for result, can be retrieved
285-
* in the calling Activity's {@link Activity#onActivityResult(int, int, Intent)} method.
302+
* in the calling Activity's {@see Activity#onActivityResult(int, int, Intent)} method.
286303
* Default is {@link #DEFAULT_SETTINGS_REQ_CODE}.
287304
*/
288305
@NonNull

0 commit comments

Comments
 (0)