Skip to content

Commit 4399218

Browse files
committed
新增api
1 parent e633d0a commit 4399218

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

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

Lines changed: 16 additions & 13 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

@@ -56,6 +54,7 @@ public class OpeninstallFlutterPlugin implements FlutterPlugin, MethodCallHandle
5654
private static final String METHOD_SHARE = "reportShare";
5755

5856
private static final String METHOD_OPID = "getOpid";
57+
private static final String METHOD_CHANNEL = "setChannel";
5958

6059
private static final String METHOD_WAKEUP_NOTIFICATION = "onWakeupNotification";
6160
private static final String METHOD_INSTALL_NOTIFICATION = "onInstallNotification";
@@ -123,9 +122,9 @@ public void onMethodCall(MethodCall call, @NonNull final Result result) {
123122
@Override
124123
public void onInstallFinish(AppData appData, Error error) {
125124
Map<String, Object> data = data2Map(appData);
126-
boolean shouldRetry = error!=null && error.shouldRetry();
125+
boolean shouldRetry = error != null && error.shouldRetry();
127126
data.put("shouldRetry", shouldRetry);
128-
if(error != null) {
127+
if (error != null) {
129128
data.put("message", error.getErrorMsg());
130129
}
131130
channel.invokeMethod(METHOD_INSTALL_NOTIFICATION, data);
@@ -150,10 +149,10 @@ public void onInstall(AppData appData, boolean shouldRetry) {
150149
} else if (METHOD_EFFECT_POINT.equalsIgnoreCase(call.method)) {
151150
String pointId = call.argument("pointId");
152151
Integer pointValue = call.argument("pointValue");
153-
if(TextUtils.isEmpty(pointId) || pointValue == null){
152+
if (TextUtils.isEmpty(pointId) || pointValue == null) {
154153
Log.w(TAG, "pointId is empty or pointValue is null");
155154
// result.error("ERROR", "pointId is empty or pointValue is null", null);
156-
}else{
155+
} else {
157156
Map<String, String> extraMap = call.argument("extras");
158157
OpenInstall.reportEffectPoint(pointId, pointValue, extraMap);
159158
}
@@ -162,17 +161,17 @@ public void onInstall(AppData appData, boolean shouldRetry) {
162161
String shareCode = call.argument("shareCode");
163162
String sharePlatform = call.argument("platform");
164163
final Map<String, Object> data = new HashMap<>();
165-
if(TextUtils.isEmpty(shareCode) || TextUtils.isEmpty(sharePlatform)){
166-
data.put("message", "shareCode or platform is empty");
164+
if (TextUtils.isEmpty(shareCode) || TextUtils.isEmpty(sharePlatform)) {
165+
data.put("message", "shareCode or platform is empty");
167166
data.put("shouldRetry", false);
168167
result.success(data);
169-
}else {
168+
} else {
170169
OpenInstall.reportShare(shareCode, sharePlatform, new ResultCallback<Void>() {
171170
@Override
172171
public void onResult(@Nullable Void v, @Nullable Error error) {
173-
boolean shouldRetry = error!=null && error.shouldRetry();
172+
boolean shouldRetry = error != null && error.shouldRetry();
174173
data.put("shouldRetry", shouldRetry);
175-
if(error != null) {
174+
if (error != null) {
176175
data.put("message", error.getErrorMsg());
177176
}
178177
result.success(data);
@@ -182,6 +181,10 @@ public void onResult(@Nullable Void v, @Nullable Error error) {
182181
} else if (METHOD_OPID.equalsIgnoreCase(call.method)) {
183182
String opid = OpenInstall.getOpid();
184183
result.success(opid);
184+
} else if (METHOD_CHANNEL.equalsIgnoreCase(call.method)) {
185+
String channelCode = call.argument("channelCode");
186+
OpenInstall.setChannel(channelCode);
187+
result.success("OK");
185188
} else {
186189
result.notImplemented();
187190
}
@@ -211,7 +214,7 @@ private void config(MethodCall call) {
211214
String gaid = call.argument("gaid");
212215
builder.gaid(gaid);
213216
}
214-
if(call.hasArgument("imeiDisabled")){
217+
if (call.hasArgument("imeiDisabled")) {
215218
Boolean imeiDisabled = call.argument("imeiDisabled");
216219
if (checkBoolean(imeiDisabled)) {
217220
builder.imeiDisabled();
@@ -221,7 +224,7 @@ private void config(MethodCall call) {
221224
String imei = call.argument("imei");
222225
builder.imei(imei);
223226
}
224-
if(call.hasArgument("macDisabled")){
227+
if (call.hasArgument("macDisabled")) {
225228
Boolean macDisabled = call.argument("macDisabled");
226229
if (checkBoolean(macDisabled)) {
227230
builder.macDisabled();

example/.flutter-plugins-dependencies

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"openinstall_flutter_plugin","path":"D:\\\\workspace\\\\op-github\\\\openinstall_flutter_plugin\\\\","dependencies":[]}],"android":[{"name":"openinstall_flutter_plugin","path":"D:\\\\workspace\\\\op-github\\\\openinstall_flutter_plugin\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"openinstall_flutter_plugin","dependencies":[]}],"date_created":"2023-07-25 15:50:36.137368","version":"2.8.1"}
1+
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"openinstall_flutter_plugin","path":"D:\\\\workspace\\\\op-github\\\\openinstall_flutter_plugin\\\\","dependencies":[]}],"android":[{"name":"openinstall_flutter_plugin","path":"D:\\\\workspace\\\\op-github\\\\openinstall_flutter_plugin\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"openinstall_flutter_plugin","dependencies":[]}],"date_created":"2023-07-27 14:42:12.574941","version":"2.8.1"}

lib/openinstall_flutter_plugin.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ class OpeninstallFlutterPlugin {
156156
return opid;
157157
}
158158

159+
void setChannel(String channelCode) {
160+
if (Platform.isAndroid) {
161+
var args = new Map();
162+
args["channelCode"] = channelCode;
163+
_channel.invokeMethod('setChannel', args);
164+
} else {
165+
// 仅使用于 Android 平台
166+
}
167+
}
168+
159169
Future _handleMethod(MethodCall call) async {
160170
print(call.method);
161171
switch (call.method) {

0 commit comments

Comments
 (0)