Skip to content

Commit 78f8158

Browse files
committed
Android SDK 升级 2.8.2
1 parent ad01e31 commit 78f8158

File tree

7 files changed

+48
-33
lines changed

7 files changed

+48
-33
lines changed

android/libs/OpenInstall_v2.8.1.jar

-98.5 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: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class OpeninstallFlutterPlugin implements FlutterPlugin, MethodCallHandle
4343
@Deprecated
4444
private static final String METHOD_WAKEUP = "registerWakeup";
4545

46+
private static final String METHOD_DEBUG = "setDebug";
4647
private static final String METHOD_CONFIG = "config";
4748
private static final String METHOD_CLIPBOARD_ENABLED = "clipBoardEnabled";
4849
private static final String METHOD_SERIAL_ENABLED = "serialEnabled";
@@ -52,7 +53,6 @@ public class OpeninstallFlutterPlugin implements FlutterPlugin, MethodCallHandle
5253
private static final String METHOD_REGISTER = "reportRegister";
5354
private static final String METHOD_EFFECT_POINT = "reportEffectPoint";
5455
private static final String METHOD_SHARE = "reportShare";
55-
5656
private static final String METHOD_OPID = "getOpid";
5757
private static final String METHOD_CHANNEL = "setChannel";
5858

@@ -67,13 +67,15 @@ public class OpeninstallFlutterPlugin implements FlutterPlugin, MethodCallHandle
6767
private Configuration configuration = null;
6868

6969
private boolean alwaysCallback = false;
70+
private boolean debuggable = true;
7071

7172

7273
@Override
7374
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
7475
flutterPluginBinding = binding;
7576
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "openinstall_flutter_plugin");
7677
channel.setMethodCallHandler(this);
78+
OpenInstall.preInit(flutterPluginBinding.getApplicationContext());
7779
}
7880

7981
@Override
@@ -92,8 +94,13 @@ public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBindin
9294

9395
@Override
9496
public void onMethodCall(MethodCall call, @NonNull final Result result) {
95-
Log.d(TAG, "invoke " + call.method);
96-
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)) {
97104
config(call);
98105
result.success("OK");
99106
} else if (METHOD_CLIPBOARD_ENABLED.equalsIgnoreCase(call.method)) {
@@ -236,7 +243,7 @@ private void config(MethodCall call) {
236243
}
237244

238245
configuration = builder.build();
239-
// 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, "
240247
// + "androidId=%s, serialNumber=%s, imei=%s, mac=%s",
241248
// configuration.isAdEnabled(), configuration.getOaid(), configuration.getGaid(),
242249
// configuration.isMacDisabled(), configuration.isImeiDisabled(),
@@ -252,56 +259,48 @@ private boolean checkBoolean(Boolean bool) {
252259

253260
private void init() {
254261
Context context = flutterPluginBinding.getApplicationContext();
255-
if (context != null) {
256-
OpenInstall.init(context, configuration);
257-
initialized = true;
258-
if (intentHolder != null) {
259-
wakeup(intentHolder);
260-
intentHolder = null;
261-
}
262-
} else {
263-
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;
264267
}
265268
}
266269

267270
@Deprecated
268271
private void initWithPermission() {
269272
Activity activity = activityPluginBinding.getActivity();
270-
if (activity == null) {
271-
Log.d(TAG, "Activity is null, can't initWithPermission, replace with init");
272-
init();
273-
} else {
274-
activityPluginBinding.addRequestPermissionsResultListener(permissionsResultListener);
275-
OpenInstall.initWithPermission(activity, configuration, new Runnable() {
276-
@Override
277-
public void run() {
278-
activityPluginBinding.removeRequestPermissionsResultListener(permissionsResultListener);
279-
initialized = true;
280-
if (intentHolder != null) {
281-
wakeup(intentHolder);
282-
intentHolder = null;
283-
}
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;
284282
}
285-
});
286-
}
283+
}
284+
});
287285
}
288286

289287
@Override
290288
public boolean onNewIntent(Intent intent) {
289+
debugLog("onNewIntent");
291290
wakeup(intent);
292291
return false;
293292
}
294293

295294

296295
private void wakeup(Intent intent) {
297296
if (initialized) {
298-
Log.d(TAG, "getWakeUp : alwaysCallback=" + alwaysCallback);
297+
debugLog("getWakeUp : alwaysCallback=" + alwaysCallback);
299298
if (alwaysCallback) {
300299
OpenInstall.getWakeUpAlwaysCallback(intent, new AppWakeUpListener() {
301300
@Override
302301
public void onWakeUpFinish(AppData appData, Error error) {
303302
if (error != null) { // 可忽略,仅调试使用
304-
Log.d(TAG, "getWakeUpAlwaysCallback : " + error.getErrorMsg());
303+
debugLog("getWakeUpAlwaysCallback : " + error.getErrorMsg());
305304
}
306305
channel.invokeMethod(METHOD_WAKEUP_NOTIFICATION, data2Map(appData));
307306
}
@@ -338,6 +337,12 @@ private static Map<String, Object> data2Map(AppData data) {
338337
return result;
339338
}
340339

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

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class _MyAppState extends State<MyApp> {
3030
if (!mounted) return;
3131

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

lib/openinstall_flutter_plugin.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ class OpeninstallFlutterPlugin {
3535
}
3636
}
3737

38+
void setDebug(bool enabled){
39+
if (Platform.isAndroid) {
40+
var args = new Map();
41+
args["enabled"] = enabled;
42+
_channel.invokeMethod('setDebug', args);
43+
} else {
44+
// 仅使用于 Android 平台
45+
}
46+
}
47+
3848
// 广告平台配置,请参考文档
3949
void configAndroid(Map options) {
4050
if (Platform.isAndroid) {

0 commit comments

Comments
 (0)