Commit d65a8692 authored by Scott's avatar Scott

更新

parent f81ae31e
# umeng_common_sdk Flutter Plugin
# 使用步骤
# 安装
# 1、安装
在工程 pubspec.yaml 中加入 dependencies
dependencies:
umeng_common_sdk: 1.2.2
umeng_common_sdk:
git:
url: git@github.com:flutter-plugin/umeng_common_flutter.git
ref: master
# 使用
# 2、使用
import 'package:umeng_common_sdk/umeng_common_sdk.dart';
**注意** : 需要先调用 UMConfigure.init 来初始化插件(Appkey可在统计后台 “管理->应用管理->应用列表” 页面查看,或在 “我的产品”选择某应用->设置->应用信息 查看Appkey),才能保证其他功能正常工作。
\ No newline at end of file
......@@ -26,23 +26,21 @@ public class UmengCommonSdkPlugin implements FlutterPlugin, MethodCallHandler {
Class<?> agent = Class.forName("com.umeng.analytics.MobclickAgent");
Method[] methods = agent.getDeclaredMethods();
for (Method m : methods) {
android.util.Log.e("UMLog", "Reflect:"+m);
if(m.getName().equals("onEventObject")) {
android.util.Log.e("UMLog", "Reflect:" + m);
if (m.getName().equals("onEventObject")) {
versionMatch = true;
break;
}
}
if(!versionMatch) {
if (!versionMatch) {
android.util.Log.e("UMLog", "安卓SDK版本过低,建议升级至8以上");
//return;
}
else {
// return;
} else {
android.util.Log.e("UMLog", "安卓依赖版本检查成功");
}
}
catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
android.util.Log.e("UMLog", "SDK版本过低,请升级至8以上"+e.toString());
android.util.Log.e("UMLog", "SDK版本过低,请升级至8以上" + e.toString());
return;
}
......@@ -51,12 +49,11 @@ public class UmengCommonSdkPlugin implements FlutterPlugin, MethodCallHandler {
Class<?> config = Class.forName("com.umeng.commonsdk.UMConfigure");
method = config.getDeclaredMethod("setWraperType", String.class, String.class);
method.setAccessible(true);
method.invoke(null, "flutter","1.0");
method.invoke(null, "flutter", "1.0");
android.util.Log.i("UMLog", "setWraperType:flutter1.0 success");
}
catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
android.util.Log.e("UMLog", "setWraperType:flutter1.0"+e.toString());
android.util.Log.e("UMLog", "setWraperType:flutter1.0" + e.toString());
}
}
......@@ -70,45 +67,43 @@ public class UmengCommonSdkPlugin implements FlutterPlugin, MethodCallHandler {
static Context mContext;
@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
if(!versionMatch) {
Log.e("UMLog", "onMethodCall:"+call.method+":安卓SDK版本过低,请升级至8以上");
if (!versionMatch) {
Log.e("UMLog", "onMethodCall:" + call.method + ":安卓SDK版本过低,请升级至8以上");
return;
}
if("preInit".equals(call.method)){
if ("preInit".equals(call.method)) {
// 自动采集选择
//MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO);
// MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO);
//手动采集选择
// 手动采集选择
MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.MANUAL);
UMConfigure.setProcessEvent(true);
String appKey = call.argument("appKey");
String channel = call.argument("channel");
boolean enableLog = call.argument("enableLog");
UMConfigure.preInit(mContext,appKey,channel);
UMConfigure.preInit(mContext, appKey, channel);
UMConfigure.setLogEnabled(enableLog);
result.success(true);
}else if("init".equals(call.method)){
} else if ("init".equals(call.method)) {
String appKey = call.argument("appKey");
String channel = call.argument("channel");
Integer deviceType = call.argument("deviceType");
String pushSecret = call.argument("pushSecret");
UMConfigure.init(mContext, appKey, channel, deviceType,
pushSecret);
UMConfigure.init(mContext, appKey, channel, deviceType, pushSecret);
result.success(true);
}else if("onEvent".equals(call.method)){
//UMConfigure.DEVICE_TYPE_PHONE
} else if ("onEvent".equals(call.method)) {
// UMConfigure.DEVICE_TYPE_PHONE
String eventId = call.argument("eventId");
Map<String,Object> properties = call.argument("properties");
MobclickAgent.onEventObject(mContext,eventId,properties);
Map<String, Object> properties = call.argument("properties");
MobclickAgent.onEventObject(mContext, eventId, properties);
MobclickAgent.setSessionContinueMillis(1000l);
MobclickAgent.setCatchUncaughtExceptions(true);
result.success(true);
}else{
} else {
result.notImplemented();
}
}
......
......@@ -20,10 +20,10 @@ class _MyAppState extends State<MyApp> {
).then((value) {}).whenComplete(() {
Future.delayed(Duration(seconds: 15), () {
UmengCommonSdk.init(
'6130b199695f794bbd9cb984',
'qiaomeng',
1,
'6130b199695f794bbd9cb984',
appKey: '6130b199695f794bbd9cb984',
channel: 'qiaomeng',
deviceType: 1,
pushSecret: '6130b199695f794bbd9cb984',
);
});
});
......@@ -38,13 +38,17 @@ class _MyAppState extends State<MyApp> {
body: Column(
children: [
TextButton(
onPressed: () async {
await UmengCommonSdk.onEvent('event_test', {
onPressed: () async {
await UmengCommonSdk.onEvent(
event: 'event_test',
properties: {
'key': '测试上传数据',
'key1': '测试上传数据',
});
},
child: Text('上报事件')),
},
);
},
child: Text('上报事件'),
),
],
),
),
......
......@@ -7,9 +7,9 @@ class UmengCommonSdk {
///
/// 预初始化
/// [appKey]
/// [channel]
/// [enableLog]
/// [appKey] 友盟控制台appKey
/// [channel] app的渠道,如:应用宝、小米、华为应用商店等
/// [enableLog] 是否启用日志
///
static Future<bool> preInit({
required String appKey,
......@@ -26,17 +26,17 @@ class UmengCommonSdk {
///
/// 初始化
/// [appKey] AppKey
/// [channel]
/// [deviceType]
/// [pushSecret]
/// [appKey] 友盟控制台appKey
/// [channel] app的渠道,如:应用宝、小米、华为应用商店等
/// [deviceType] 设备类型1、手机、2、...
/// [pushSecret] 密钥
///
static Future<bool> init(
String appKey,
String channel,
int deviceType,
String pushSecret,
) async {
static Future<bool> init({
required String appKey,
required String channel,
int deviceType = 1,
String? pushSecret,
}) async {
final dynamic result = await _channel.invokeMethod('init', {
'appKey': appKey,
'channel': channel,
......@@ -51,8 +51,10 @@ class UmengCommonSdk {
/// [event] 事件标志
/// [properties] 事件参数
///
static Future<bool> onEvent(
String event, Map<String, dynamic> properties) async {
static Future<bool> onEvent({
required String event,
required Map<String, dynamic> properties,
}) async {
return await _channel.invokeMethod('onEvent', {
'eventId': event,
'properties': properties,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment