7
7
import android .os .Parcel ;
8
8
import android .os .Parcelable ;
9
9
import android .text .TextUtils ;
10
+ import android .util .Log ;
10
11
11
12
import androidx .annotation .NonNull ;
12
13
import androidx .annotation .Nullable ;
19
20
/**
20
21
* Dialog to prompt the user to go to the app's settings screen and enable permissions. If the user
21
22
* 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)}.
23
24
* <p>
24
25
* Use the {@link Builder} to create and display a dialog.
25
26
*/
26
27
public class AppSettingsDialog implements Parcelable {
28
+
29
+ private static final String TAG = "EasyPermissions" ;
30
+
27
31
public static final int DEFAULT_SETTINGS_REQ_CODE = 16061 ;
28
32
29
33
@ RestrictTo (RestrictTo .Scope .LIBRARY_GROUP )
@@ -83,6 +87,19 @@ private AppSettingsDialog(@NonNull final Object activityOrFragment,
83
87
84
88
static AppSettingsDialog fromIntent (Intent intent , Activity activity ) {
85
89
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
+
86
103
dialog .setActivityOrFragment (activity );
87
104
return dialog ;
88
105
}
@@ -261,7 +278,7 @@ public Builder setPositiveButton(@StringRes int textId) {
261
278
* Set the negative button text, default is {@link android.R.string#cancel}.
262
279
* <p>
263
280
* 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
265
282
* Activity#onActivityResult(int, int, Intent)}. If you still don't have the right
266
283
* permissions, then the request was cancelled.
267
284
*/
@@ -282,7 +299,7 @@ public Builder setNegativeButton(@StringRes int textId) {
282
299
283
300
/**
284
301
* 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.
286
303
* Default is {@link #DEFAULT_SETTINGS_REQ_CODE}.
287
304
*/
288
305
@ NonNull
0 commit comments