Skip to content

Commit 071db71

Browse files
committed
2 parents 247c67e + 9bf84dd commit 071db71

File tree

10 files changed

+127
-73
lines changed

10 files changed

+127
-73
lines changed

CHANGELOG.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
## 2.4.2
2+
Android 更新 SDK 到 2.8.2
3+
4+
## 2.4.1
5+
Android 更新 SDK 到 2.8.1
6+
iOS 更新本地pod库使SDK升级到2.8.0
17

28
## 2.4.0
39
新增裂变分享统计
4-
Android 更新 SDK 到 2.8.0
5-
iOS
6-
getInstall新增返回码shouldRetry,超时返回true
7-
更新本地pod库使SDK升级到2.7.0
10+
getInstall新增返回码shouldRetry,超时返回true
11+
Android 更新 SDK 到 2.8.0
12+
iOS 更新本地pod库使SDK升级到2.7.0
813

914
## 2.3.1
1015
iOS
@@ -15,15 +20,15 @@ getInstall新增返回码shouldRetry,超时返回true
1520

1621
## 2.3.0
1722
新增效果点明细API
18-
Android 更新 SDK 到 2.7.0
23+
Android 更新 SDK 到 2.7.0
1924
iOS端插件升级后,需要从cocoapod同步升级原生SDK到2.6.0以上
2025

2126
## 2.2.3
2227
Android 更新 SDK 到 2.6.4
2328

2429
## 2.2.2
25-
Android 更新 SDK 到 2.6.3
26-
iOS 更新 SDK 到 2.5.5
30+
Android 更新 SDK 到 2.6.3
31+
iOS 更新 SDK 到 2.5.5
2732
将 dynamic 替换为 Object
2833

2934
## 2.2.1

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ android: {
1818
....
1919
defaultConfig {
2020
...
21-
manifestPlaceholders = [
21+
manifestPlaceholders += [
2222
OPENINSTALL_APPKEY : "openinstall为应用分配的appkey",
2323
]
2424
}
@@ -184,7 +184,7 @@ swift代码:
184184

185185
示例:
186186
``` dart
187-
Future wakeupHandler(Map<String, dynamic> data) async {
187+
Future wakeupHandler(Map<String, Object> data) async {
188188
setState(() {
189189
debugLog = "wakeup result : channel=" +
190190
data['channelCode'] +
@@ -203,7 +203,7 @@ _openinstallFlutterPlugin.init(wakeupHandler);
203203
示例:
204204
``` dart
205205
206-
Future installHandler(Map<String, dynamic> data) async {
206+
Future installHandler(Map<String, Object> data) async {
207207
setState(() {
208208
debugLog = "install result : channel=" +
209209
data['channelCode'] +

android/libs/OpenInstall_v2.8.0.jar

-97.1 KB
Binary file not shown.

android/libs/OpenInstall_v2.8.2.jar

99 KB
Binary file not shown.

android/src/main/java/io/openinstall/openinstall_flutter_plugin/OpeninstallFlutterPlugin.java

Lines changed: 70 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import com.fm.openinstall.Configuration;
1313
import com.fm.openinstall.OpenInstall;
14-
import com.fm.openinstall.listener.AppInstallAdapter;
1514
import com.fm.openinstall.listener.AppInstallListener;
1615
import com.fm.openinstall.listener.AppInstallRetryAdapter;
1716
import com.fm.openinstall.listener.AppWakeUpAdapter;
@@ -20,7 +19,6 @@
2019
import com.fm.openinstall.model.AppData;
2120
import com.fm.openinstall.model.Error;
2221

23-
import java.util.Collections;
2422
import java.util.HashMap;
2523
import java.util.Map;
2624

@@ -45,6 +43,7 @@ public class OpeninstallFlutterPlugin implements FlutterPlugin, MethodCallHandle
4543
@Deprecated
4644
private static final String METHOD_WAKEUP = "registerWakeup";
4745

46+
private static final String METHOD_DEBUG = "setDebug";
4847
private static final String METHOD_CONFIG = "config";
4948
private static final String METHOD_CLIPBOARD_ENABLED = "clipBoardEnabled";
5049
private static final String METHOD_SERIAL_ENABLED = "serialEnabled";
@@ -54,6 +53,8 @@ public class OpeninstallFlutterPlugin implements FlutterPlugin, MethodCallHandle
5453
private static final String METHOD_REGISTER = "reportRegister";
5554
private static final String METHOD_EFFECT_POINT = "reportEffectPoint";
5655
private static final String METHOD_SHARE = "reportShare";
56+
private static final String METHOD_OPID = "getOpid";
57+
private static final String METHOD_CHANNEL = "setChannel";
5758

5859
private static final String METHOD_WAKEUP_NOTIFICATION = "onWakeupNotification";
5960
private static final String METHOD_INSTALL_NOTIFICATION = "onInstallNotification";
@@ -66,13 +67,15 @@ public class OpeninstallFlutterPlugin implements FlutterPlugin, MethodCallHandle
6667
private Configuration configuration = null;
6768

6869
private boolean alwaysCallback = false;
70+
private boolean debuggable = true;
6971

7072

7173
@Override
7274
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
7375
flutterPluginBinding = binding;
7476
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "openinstall_flutter_plugin");
7577
channel.setMethodCallHandler(this);
78+
OpenInstall.preInit(flutterPluginBinding.getApplicationContext());
7679
}
7780

7881
@Override
@@ -91,8 +94,13 @@ public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBindin
9194

9295
@Override
9396
public void onMethodCall(MethodCall call, @NonNull final Result result) {
94-
Log.d(TAG, "invoke " + call.method);
95-
if (METHOD_CONFIG.equalsIgnoreCase(call.method)) {
97+
debugLog("invoke " + call.method);
98+
if (METHOD_DEBUG.equalsIgnoreCase(call.method)) {
99+
Boolean enabled = call.argument("enabled");
100+
debuggable = enabled == null ? true : enabled;
101+
OpenInstall.setDebug(debuggable);
102+
result.success("OK");
103+
} else if (METHOD_CONFIG.equalsIgnoreCase(call.method)) {
96104
config(call);
97105
result.success("OK");
98106
} else if (METHOD_CLIPBOARD_ENABLED.equalsIgnoreCase(call.method)) {
@@ -120,21 +128,24 @@ public void onMethodCall(MethodCall call, @NonNull final Result result) {
120128
OpenInstall.getInstall(new AppInstallListener() {
121129
@Override
122130
public void onInstallFinish(AppData appData, Error error) {
123-
Map<String, String> data = data2Map(appData);
124-
boolean shouldRetry = error!=null && error.shouldRetry();
125-
data.put("shouldRetry", String.valueOf(shouldRetry));
126-
channel.invokeMethod(METHOD_INSTALL_NOTIFICATION,data );
131+
Map<String, Object> data = data2Map(appData);
132+
boolean shouldRetry = error != null && error.shouldRetry();
133+
data.put("shouldRetry", shouldRetry);
134+
if (error != null) {
135+
data.put("message", error.getErrorMsg());
136+
}
137+
channel.invokeMethod(METHOD_INSTALL_NOTIFICATION, data);
127138
}
128139
}, seconds == null ? 0 : seconds);
129140
result.success("OK");
130141
} else if (METHOD_INSTALL_RETRY.equalsIgnoreCase(call.method)) {
131142
Integer seconds = call.argument("seconds");
132143
OpenInstall.getInstallCanRetry(new AppInstallRetryAdapter() {
133144
@Override
134-
public void onInstall(AppData appData, boolean retry) {
135-
Map<String, String> data = data2Map(appData);
136-
data.put("retry", String.valueOf(retry));
137-
data.put("shouldRetry", String.valueOf(retry)); // 以后保存统一
145+
public void onInstall(AppData appData, boolean shouldRetry) {
146+
Map<String, Object> data = data2Map(appData);
147+
data.put("retry", String.valueOf(shouldRetry)); // 2.4.0 之前的版本返回
148+
data.put("shouldRetry", shouldRetry); // 以后保存统一
138149
channel.invokeMethod(METHOD_INSTALL_NOTIFICATION, data);
139150
}
140151
}, seconds == null ? 0 : seconds);
@@ -145,35 +156,42 @@ public void onInstall(AppData appData, boolean retry) {
145156
} else if (METHOD_EFFECT_POINT.equalsIgnoreCase(call.method)) {
146157
String pointId = call.argument("pointId");
147158
Integer pointValue = call.argument("pointValue");
148-
if(TextUtils.isEmpty(pointId) || pointValue == null){
159+
if (TextUtils.isEmpty(pointId) || pointValue == null) {
149160
Log.w(TAG, "pointId is empty or pointValue is null");
150161
// result.error("ERROR", "pointId is empty or pointValue is null", null);
151-
}else{
162+
} else {
152163
Map<String, String> extraMap = call.argument("extras");
153164
OpenInstall.reportEffectPoint(pointId, pointValue, extraMap);
154165
}
155166
result.success("OK");
156167
} else if (METHOD_SHARE.equalsIgnoreCase(call.method)) {
157168
String shareCode = call.argument("shareCode");
158169
String sharePlatform = call.argument("platform");
159-
final Map<String, String> data = new HashMap<>();
160-
if(TextUtils.isEmpty(shareCode) || TextUtils.isEmpty(sharePlatform)){
161-
data.put("message", "shareCode or platform is empty");
162-
data.put("shouldRetry", String.valueOf(false));
170+
final Map<String, Object> data = new HashMap<>();
171+
if (TextUtils.isEmpty(shareCode) || TextUtils.isEmpty(sharePlatform)) {
172+
data.put("message", "shareCode or platform is empty");
173+
data.put("shouldRetry", false);
163174
result.success(data);
164-
}else {
175+
} else {
165176
OpenInstall.reportShare(shareCode, sharePlatform, new ResultCallback<Void>() {
166177
@Override
167178
public void onResult(@Nullable Void v, @Nullable Error error) {
168-
boolean shouldRetry = error!=null && error.shouldRetry();
169-
data.put("shouldRetry", String.valueOf(shouldRetry));
170-
if(error != null) {
179+
boolean shouldRetry = error != null && error.shouldRetry();
180+
data.put("shouldRetry", shouldRetry);
181+
if (error != null) {
171182
data.put("message", error.getErrorMsg());
172183
}
173184
result.success(data);
174185
}
175186
});
176187
}
188+
} else if (METHOD_OPID.equalsIgnoreCase(call.method)) {
189+
String opid = OpenInstall.getOpid();
190+
result.success(opid);
191+
} else if (METHOD_CHANNEL.equalsIgnoreCase(call.method)) {
192+
String channelCode = call.argument("channelCode");
193+
OpenInstall.setChannel(channelCode);
194+
result.success("OK");
177195
} else {
178196
result.notImplemented();
179197
}
@@ -203,7 +221,7 @@ private void config(MethodCall call) {
203221
String gaid = call.argument("gaid");
204222
builder.gaid(gaid);
205223
}
206-
if(call.hasArgument("imeiDisabled")){
224+
if (call.hasArgument("imeiDisabled")) {
207225
Boolean imeiDisabled = call.argument("imeiDisabled");
208226
if (checkBoolean(imeiDisabled)) {
209227
builder.imeiDisabled();
@@ -213,7 +231,7 @@ private void config(MethodCall call) {
213231
String imei = call.argument("imei");
214232
builder.imei(imei);
215233
}
216-
if(call.hasArgument("macDisabled")){
234+
if (call.hasArgument("macDisabled")) {
217235
Boolean macDisabled = call.argument("macDisabled");
218236
if (checkBoolean(macDisabled)) {
219237
builder.macDisabled();
@@ -225,7 +243,7 @@ private void config(MethodCall call) {
225243
}
226244

227245
configuration = builder.build();
228-
// Log.d(TAG, String.format("Configuration: adEnabled=%s, oaid=%s, gaid=%s, macDisabled=%s, imeiDisabled=%s, "
246+
// debugLog(String.format("Configuration: adEnabled=%s, oaid=%s, gaid=%s, macDisabled=%s, imeiDisabled=%s, "
229247
// + "androidId=%s, serialNumber=%s, imei=%s, mac=%s",
230248
// configuration.isAdEnabled(), configuration.getOaid(), configuration.getGaid(),
231249
// configuration.isMacDisabled(), configuration.isImeiDisabled(),
@@ -241,56 +259,48 @@ private boolean checkBoolean(Boolean bool) {
241259

242260
private void init() {
243261
Context context = flutterPluginBinding.getApplicationContext();
244-
if (context != null) {
245-
OpenInstall.init(context, configuration);
246-
initialized = true;
247-
if (intentHolder != null) {
248-
wakeup(intentHolder);
249-
intentHolder = null;
250-
}
251-
} else {
252-
Log.d(TAG, "Context is null, can't init");
262+
OpenInstall.init(context, configuration);
263+
initialized = true;
264+
if (intentHolder != null) {
265+
wakeup(intentHolder);
266+
intentHolder = null;
253267
}
254268
}
255269

256270
@Deprecated
257271
private void initWithPermission() {
258272
Activity activity = activityPluginBinding.getActivity();
259-
if (activity == null) {
260-
Log.d(TAG, "Activity is null, can't initWithPermission, replace with init");
261-
init();
262-
} else {
263-
activityPluginBinding.addRequestPermissionsResultListener(permissionsResultListener);
264-
OpenInstall.initWithPermission(activity, configuration, new Runnable() {
265-
@Override
266-
public void run() {
267-
activityPluginBinding.removeRequestPermissionsResultListener(permissionsResultListener);
268-
initialized = true;
269-
if (intentHolder != null) {
270-
wakeup(intentHolder);
271-
intentHolder = null;
272-
}
273+
activityPluginBinding.addRequestPermissionsResultListener(permissionsResultListener);
274+
OpenInstall.initWithPermission(activity, configuration, new Runnable() {
275+
@Override
276+
public void run() {
277+
activityPluginBinding.removeRequestPermissionsResultListener(permissionsResultListener);
278+
initialized = true;
279+
if (intentHolder != null) {
280+
wakeup(intentHolder);
281+
intentHolder = null;
273282
}
274-
});
275-
}
283+
}
284+
});
276285
}
277286

278287
@Override
279288
public boolean onNewIntent(Intent intent) {
289+
debugLog("onNewIntent");
280290
wakeup(intent);
281291
return false;
282292
}
283293

284294

285295
private void wakeup(Intent intent) {
286296
if (initialized) {
287-
Log.d(TAG, "getWakeUp : alwaysCallback=" + alwaysCallback);
297+
debugLog("getWakeUp : alwaysCallback=" + alwaysCallback);
288298
if (alwaysCallback) {
289299
OpenInstall.getWakeUpAlwaysCallback(intent, new AppWakeUpListener() {
290300
@Override
291301
public void onWakeUpFinish(AppData appData, Error error) {
292302
if (error != null) { // 可忽略,仅调试使用
293-
Log.d(TAG, "getWakeUpAlwaysCallback : " + error.getErrorMsg());
303+
debugLog("getWakeUpAlwaysCallback : " + error.getErrorMsg());
294304
}
295305
channel.invokeMethod(METHOD_WAKEUP_NOTIFICATION, data2Map(appData));
296306
}
@@ -318,15 +328,21 @@ public boolean onRequestPermissionsResult(int requestCode, String[] permissions,
318328
}
319329
};
320330

321-
private static Map<String, String> data2Map(AppData data) {
322-
Map<String, String> result = new HashMap<>();
331+
private static Map<String, Object> data2Map(AppData data) {
332+
Map<String, Object> result = new HashMap<>();
323333
if (data != null) {
324334
result.put("channelCode", data.getChannel());
325335
result.put("bindData", data.getData());
326336
}
327337
return result;
328338
}
329339

340+
private void debugLog(String message) {
341+
if (debuggable) {
342+
Log.d(TAG, message);
343+
}
344+
}
345+
330346
@Override
331347
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
332348

example/.flutter-plugins-dependencies

Lines changed: 0 additions & 1 deletion
This file was deleted.

example/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
**/doc/api/
2323
.dart_tool/
2424
.flutter-plugins
25+
.flutter-plugins-dependencies
2526
.packages
2627
.pub-cache/
2728
.pub/

example/lib/main.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ class _MyAppState extends State<MyApp> {
3030
if (!mounted) return;
3131

3232
_openinstallFlutterPlugin = OpeninstallFlutterPlugin();
33-
33+
// _openinstallFlutterPlugin.setDebug(false);
3434
_openinstallFlutterPlugin.init(wakeupHandler);
35-
_openinstallFlutterPlugin.install(installHandler);
35+
// 错误:应该在业务需要时再调用 install 获取参数
36+
// _openinstallFlutterPlugin.install(installHandler);
3637

3738
setState(() {});
3839
}
@@ -53,7 +54,7 @@ class _MyAppState extends State<MyApp> {
5354
const SizedBox(height: 12),
5455
ElevatedButton(
5556
onPressed: () {
56-
_openinstallFlutterPlugin.install(installHandler, 11);
57+
_openinstallFlutterPlugin.install(installHandler, 10);
5758
},
5859
child: Text('getInstall', style: TextStyle(fontSize: 16)),
5960
),
@@ -113,6 +114,7 @@ class _MyAppState extends State<MyApp> {
113114
"\n" +
114115
data['shouldRetry'].toString();
115116
});
117+
116118
}
117119

118120
Future wakeupHandler(Map<String, Object> data) async {

0 commit comments

Comments
 (0)