@@ -46,37 +46,45 @@ public class PermissionsActivity extends Activity {
46
46
// TODO this will be removed once the handled is deleted
47
47
// Default animation duration in milliseconds
48
48
private static final int DELAY_TIME_CALLBACK_CALL = 500 ;
49
- private static final int REQUEST_LOCATION = 2 ;
49
+ private static final int ONESIGNAL_PERMISSION_REQUEST_CODE = 2 ;
50
50
private static final int REQUEST_SETTINGS = 3 ;
51
51
52
52
static boolean waiting , answered , fallbackToSettings , neverAskAgainClicked ;
53
53
private static ActivityLifecycleHandler .ActivityAvailableListener activityAvailableListener ;
54
54
55
+ private static final String INTENT_EXTRA_PERMISSION_TYPE = "INTENT_EXTRA_PERMISSION_TYPE" ;
56
+ private static final String INTENT_EXTRA_ANDROID_PERMISSION_STRING = "INTENT_EXTRA_ANDROID_PERMISSION_STRING" ;
57
+ private String permissionRequestType ;
58
+
55
59
@ Override
56
60
protected void onCreate (Bundle savedInstanceState ) {
57
61
super .onCreate (savedInstanceState );
58
-
59
62
OneSignal .initWithContext (this );
60
63
61
- // Android sets android:hasCurrentPermissionsRequest if the Activity was recreated while
62
- // the permission prompt is showing to the user.
63
- // This can happen if the task is cold resumed from the Recent Apps list.
64
- if (savedInstanceState != null &&
65
- savedInstanceState .getBoolean ("android:hasCurrentPermissionsRequest" , false ))
66
- waiting = true ;
67
- else
68
- requestPermission ();
64
+ handleBundleParams (getIntent ().getExtras ());
65
+
66
+ // TODO: Very unlikely we need to handle this special case, but come back and confirm
67
+ // // Android sets android:hasCurrentPermissionsRequest if the Activity was recreated while
68
+ // // the permission prompt is showing to the user.
69
+ // // This can happen if the task is cold resumed from the Recent Apps list.
70
+ // if (savedInstanceState != null &&
71
+ // savedInstanceState.getBoolean("android:hasCurrentPermissionsRequest", false))
72
+ // waiting = true;
73
+ // else
74
+ // requestPermission();
69
75
}
70
76
71
77
@ Override
72
78
protected void onNewIntent (Intent intent ) {
73
79
super .onNewIntent (intent );
80
+ handleBundleParams (intent .getExtras ());
74
81
75
- if (OneSignal .isInitDone ())
76
- requestPermission ();
82
+ // TODO: Confirm if we still need this check
83
+ // if (OneSignal.isInitDone())
84
+ // requestPermission();
77
85
}
78
86
79
- private void requestPermission ( ) {
87
+ private void handleBundleParams ( Bundle extras ) {
80
88
// https://github.com/OneSignal/OneSignal-Android-SDK/issues/30
81
89
// Activity maybe invoked directly through automated testing, omit prompting on old Android versions.
82
90
if (Build .VERSION .SDK_INT < 23 ) {
@@ -85,10 +93,16 @@ private void requestPermission() {
85
93
return ;
86
94
}
87
95
96
+ permissionRequestType = extras .getString (INTENT_EXTRA_PERMISSION_TYPE );
97
+ String androidPermissionString = extras .getString (INTENT_EXTRA_ANDROID_PERMISSION_STRING );
98
+ requestPermission (androidPermissionString );
99
+ }
100
+
101
+ private void requestPermission (String androidPermissionString ) {
88
102
if (!waiting ) {
89
103
waiting = true ;
90
- neverAskAgainClicked = !ActivityCompat .shouldShowRequestPermissionRationale (PermissionsActivity .this , LocationController . requestPermission );
91
- ActivityCompat .requestPermissions (this , new String []{LocationController . requestPermission }, REQUEST_LOCATION );
104
+ neverAskAgainClicked = !ActivityCompat .shouldShowRequestPermissionRationale (PermissionsActivity .this , androidPermissionString );
105
+ ActivityCompat .requestPermissions (this , new String []{androidPermissionString }, ONESIGNAL_PERMISSION_REQUEST_CODE );
92
106
}
93
107
}
94
108
@@ -103,7 +117,7 @@ public void onRequestPermissionsResult(final int requestCode, @NonNull String pe
103
117
// Current problem: IAM depends on an activity, because of prompt permission the evaluation of IAM
104
118
// is being called before the prompt activity dismisses, so it's attaching the IAM to PermissionActivity
105
119
// We need to wait for other activity to show
106
- if (requestCode == REQUEST_LOCATION ) {
120
+ if (requestCode == ONESIGNAL_PERMISSION_REQUEST_CODE ) {
107
121
new Handler ().postDelayed (new Runnable () {
108
122
@ Override
109
123
public void run () {
@@ -119,6 +133,7 @@ public void run() {
119
133
}
120
134
}, DELAY_TIME_CALLBACK_CALL );
121
135
}
136
+
122
137
ActivityLifecycleHandler activityLifecycleHandler = ActivityLifecycleListener .getActivityLifecycleHandler ();
123
138
if (activityLifecycleHandler != null )
124
139
activityLifecycleHandler .removeActivityAvailableListener (TAG );
@@ -154,7 +169,7 @@ public void onClick(DialogInterface dialog, int which) {
154
169
.show ();
155
170
}
156
171
157
- static void startPrompt (boolean fallbackCondition ) {
172
+ static void startPrompt (boolean fallbackCondition , String permissionRequestType , String androidPermissionString ) {
158
173
if (PermissionsActivity .waiting || PermissionsActivity .answered )
159
174
return ;
160
175
@@ -165,6 +180,8 @@ public void available(@NonNull Activity activity) {
165
180
if (!activity .getClass ().equals (PermissionsActivity .class )) {
166
181
Intent intent = new Intent (activity , PermissionsActivity .class );
167
182
intent .setFlags (Intent .FLAG_ACTIVITY_REORDER_TO_FRONT );
183
+ intent .putExtra (INTENT_EXTRA_PERMISSION_TYPE , permissionRequestType )
184
+ .putExtra (INTENT_EXTRA_ANDROID_PERMISSION_STRING , androidPermissionString );
168
185
activity .startActivity (intent );
169
186
activity .overridePendingTransition (R .anim .onesignal_fade_in , R .anim .onesignal_fade_out );
170
187
}
0 commit comments