31
31
/**
32
32
* OpeninstallFlutterPlugin
33
33
*/
34
- public class OpeninstallFlutterPlugin implements FlutterPlugin , MethodCallHandler , ActivityAware {
34
+ public class OpeninstallFlutterPlugin implements FlutterPlugin , MethodCallHandler , ActivityAware , PluginRegistry . NewIntentListener {
35
35
36
36
private static final String TAG = "OpenInstallPlugin" ;
37
37
38
- private static final String METHOD_CONFIG = "config" ;
39
- private static final String METHOD_INIT = "init" ;
38
+ @ Deprecated
40
39
private static final String METHOD_INIT_PERMISSION = "initWithPermission" ;
40
+ @ Deprecated
41
41
private static final String METHOD_WAKEUP = "registerWakeup" ;
42
- private static final String METHOD_INSTALL = "getInstall" ;
42
+
43
+ private static final String METHOD_CONFIG = "config" ;
44
+ private static final String METHOD_INIT = "init" ;
43
45
private static final String METHOD_INSTALL_RETRY = "getInstallCanRetry" ;
46
+ private static final String METHOD_INSTALL = "getInstall" ;
44
47
private static final String METHOD_REGISTER = "reportRegister" ;
45
48
private static final String METHOD_EFFECT_POINT = "reportEffectPoint" ;
46
49
@@ -67,12 +70,20 @@ public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
67
70
@ Override
68
71
public void onAttachedToActivity (@ NonNull ActivityPluginBinding binding ) {
69
72
activityPluginBinding = binding ;
70
- activityPluginBinding .addOnNewIntentListener (newIntentListener );
73
+
74
+ binding .addOnNewIntentListener (this );
75
+ wakeup (binding .getActivity ().getIntent ());
76
+ }
77
+
78
+ @ Override
79
+ public void onReattachedToActivityForConfigChanges (@ NonNull ActivityPluginBinding binding ) {
80
+ activityPluginBinding = binding ;
81
+ binding .addOnNewIntentListener (this );
71
82
}
72
83
73
84
@ Override
74
85
public void onMethodCall (MethodCall call , @ NonNull Result result ) {
75
- Log .d (TAG , "call method " + call .method );
86
+ Log .d (TAG , "invoke " + call .method );
76
87
if (METHOD_CONFIG .equalsIgnoreCase (call .method )) {
77
88
String oaid = call .argument ("oaid" );
78
89
String gaid = call .argument ("gaid" );
@@ -86,13 +97,8 @@ public void onMethodCall(MethodCall call, @NonNull Result result) {
86
97
init ();
87
98
result .success ("OK" );
88
99
} else if (METHOD_INIT_PERMISSION .equalsIgnoreCase (call .method )) {
89
- Activity activity = activityPluginBinding .getActivity ();
90
- if (activity != null ) {
91
- initWithPermission (activity );
92
- } else {
93
- Log .d (TAG , "Activity is null, can't call initWithPermission" );
94
- init ();
95
- }
100
+ alwaysCallback = call .argument ("alwaysCallback" );
101
+ initWithPermission ();
96
102
result .success ("OK" );
97
103
} else if (METHOD_WAKEUP .equalsIgnoreCase (call .method )) {
98
104
result .success ("OK" );
@@ -158,76 +164,71 @@ private void init() {
158
164
if (context != null ) {
159
165
OpenInstall .init (context , configuration );
160
166
initialized = true ;
161
- if (intentHolder == null ) {
162
- Activity activity = activityPluginBinding .getActivity ();
163
- if (activity != null ) {
164
- wakeup (activity .getIntent ());
165
- }
166
- } else {
167
+ if (intentHolder != null ) {
167
168
wakeup (intentHolder );
168
169
intentHolder = null ;
169
170
}
170
171
} else {
171
- Log .d (TAG , "Context is null, can not init OpenInstall " );
172
+ Log .d (TAG , "Context is null, can't init" );
172
173
}
173
174
}
174
175
175
- private void initWithPermission (final Activity activity ) {
176
+ @ Deprecated
177
+ private void initWithPermission () {
178
+ Activity activity = activityPluginBinding .getActivity ();
176
179
if (activity == null ) {
177
- return ;
178
- }
179
- activityPluginBinding .addRequestPermissionsResultListener (permissionsResultListener );
180
- OpenInstall .initWithPermission (activity , configuration , new Runnable () {
181
- @ Override
182
- public void run () {
183
- activityPluginBinding .removeRequestPermissionsResultListener (permissionsResultListener );
184
- initialized = true ;
185
- if (intentHolder == null ) {
186
- wakeup (activity .getIntent ());
187
- } else {
188
- wakeup (intentHolder );
189
- intentHolder = null ;
190
- }
191
- }
192
- });
193
-
194
- }
195
-
196
- private final PluginRegistry .NewIntentListener newIntentListener =
197
- new PluginRegistry .NewIntentListener () {
180
+ Log .d (TAG , "Activity is null, can't initWithPermission, replace with init" );
181
+ init ();
182
+ } else {
183
+ activityPluginBinding .addRequestPermissionsResultListener (permissionsResultListener );
184
+ OpenInstall .initWithPermission (activity , configuration , new Runnable () {
198
185
@ Override
199
- public boolean onNewIntent (Intent intent ) {
200
- if (initialized ) {
201
- wakeup (intent );
202
- } else {
203
- intentHolder = intent ;
186
+ public void run () {
187
+ activityPluginBinding .removeRequestPermissionsResultListener (permissionsResultListener );
188
+ initialized = true ;
189
+ if (intentHolder != null ) {
190
+ wakeup (intentHolder );
191
+ intentHolder = null ;
204
192
}
205
- return false ;
206
193
}
207
- };
194
+ });
195
+ }
196
+ }
197
+
198
+ @ Override
199
+ public boolean onNewIntent (Intent intent ) {
200
+ wakeup (intent );
201
+ return false ;
202
+ }
208
203
209
204
210
205
private void wakeup (Intent intent ) {
211
- if (alwaysCallback ) {
212
- OpenInstall .getWakeUpAlwaysCallback (intent , new AppWakeUpListener () {
213
- @ Override
214
- public void onWakeUpFinish (AppData appData , Error error ) {
215
- if (error != null ) {
216
- Log .d (TAG , "getWakeUpAlwaysCallback : " + error .toString ());
206
+ if (initialized ) {
207
+ Log .d (TAG , "getWakeUp : alwaysCallback=" + alwaysCallback );
208
+ if (alwaysCallback ) {
209
+ OpenInstall .getWakeUpAlwaysCallback (intent , new AppWakeUpListener () {
210
+ @ Override
211
+ public void onWakeUpFinish (AppData appData , Error error ) {
212
+ if (error != null ) { // 可忽略,仅调试使用
213
+ Log .d (TAG , "getWakeUpAlwaysCallback : " + error .getErrorMsg ());
214
+ }
215
+ channel .invokeMethod (METHOD_WAKEUP_NOTIFICATION , data2Map (appData ));
217
216
}
218
- channel .invokeMethod (METHOD_WAKEUP_NOTIFICATION , data2Map (appData ));
219
- }
220
- });
217
+ });
218
+ } else {
219
+ OpenInstall .getWakeUp (intent , new AppWakeUpAdapter () {
220
+ @ Override
221
+ public void onWakeUp (AppData appData ) {
222
+ channel .invokeMethod (METHOD_WAKEUP_NOTIFICATION , data2Map (appData ));
223
+ }
224
+ });
225
+ }
221
226
} else {
222
- OpenInstall .getWakeUp (intent , new AppWakeUpAdapter () {
223
- @ Override
224
- public void onWakeUp (AppData appData ) {
225
- channel .invokeMethod (METHOD_WAKEUP_NOTIFICATION , data2Map (appData ));
226
- }
227
- });
227
+ intentHolder = intent ;
228
228
}
229
229
}
230
230
231
+ @ Deprecated
231
232
private final PluginRegistry .RequestPermissionsResultListener permissionsResultListener =
232
233
new PluginRegistry .RequestPermissionsResultListener () {
233
234
@ Override
@@ -256,11 +257,6 @@ public void onDetachedFromActivityForConfigChanges() {
256
257
257
258
}
258
259
259
- @ Override
260
- public void onReattachedToActivityForConfigChanges (@ NonNull ActivityPluginBinding binding ) {
261
-
262
- }
263
-
264
260
@ Override
265
261
public void onDetachedFromActivity () {
266
262
0 commit comments