Commit d65a8692 authored by Scott's avatar Scott

更新

parent f81ae31e
# umeng_common_sdk Flutter Plugin # 使用步骤
# 安装 # 1、安装
在工程 pubspec.yaml 中加入 dependencies 在工程 pubspec.yaml 中加入 dependencies
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'; 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 { ...@@ -26,23 +26,21 @@ public class UmengCommonSdkPlugin implements FlutterPlugin, MethodCallHandler {
Class<?> agent = Class.forName("com.umeng.analytics.MobclickAgent"); Class<?> agent = Class.forName("com.umeng.analytics.MobclickAgent");
Method[] methods = agent.getDeclaredMethods(); Method[] methods = agent.getDeclaredMethods();
for (Method m : methods) { for (Method m : methods) {
android.util.Log.e("UMLog", "Reflect:"+m); android.util.Log.e("UMLog", "Reflect:" + m);
if(m.getName().equals("onEventObject")) { if (m.getName().equals("onEventObject")) {
versionMatch = true; versionMatch = true;
break; break;
} }
} }
if(!versionMatch) { if (!versionMatch) {
android.util.Log.e("UMLog", "安卓SDK版本过低,建议升级至8以上"); android.util.Log.e("UMLog", "安卓SDK版本过低,建议升级至8以上");
//return; // return;
} } else {
else {
android.util.Log.e("UMLog", "安卓依赖版本检查成功"); android.util.Log.e("UMLog", "安卓依赖版本检查成功");
} }
} } catch (Exception e) {
catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
android.util.Log.e("UMLog", "SDK版本过低,请升级至8以上"+e.toString()); android.util.Log.e("UMLog", "SDK版本过低,请升级至8以上" + e.toString());
return; return;
} }
...@@ -51,12 +49,11 @@ public class UmengCommonSdkPlugin implements FlutterPlugin, MethodCallHandler { ...@@ -51,12 +49,11 @@ public class UmengCommonSdkPlugin implements FlutterPlugin, MethodCallHandler {
Class<?> config = Class.forName("com.umeng.commonsdk.UMConfigure"); Class<?> config = Class.forName("com.umeng.commonsdk.UMConfigure");
method = config.getDeclaredMethod("setWraperType", String.class, String.class); method = config.getDeclaredMethod("setWraperType", String.class, String.class);
method.setAccessible(true); method.setAccessible(true);
method.invoke(null, "flutter","1.0"); method.invoke(null, "flutter", "1.0");
android.util.Log.i("UMLog", "setWraperType:flutter1.0 success"); android.util.Log.i("UMLog", "setWraperType:flutter1.0 success");
} } catch (Exception e) {
catch (Exception e) {
e.printStackTrace(); 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 { ...@@ -70,45 +67,43 @@ public class UmengCommonSdkPlugin implements FlutterPlugin, MethodCallHandler {
static Context mContext; static Context mContext;
@Override @Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
if(!versionMatch) { if (!versionMatch) {
Log.e("UMLog", "onMethodCall:"+call.method+":安卓SDK版本过低,请升级至8以上"); Log.e("UMLog", "onMethodCall:" + call.method + ":安卓SDK版本过低,请升级至8以上");
return; 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); MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.MANUAL);
UMConfigure.setProcessEvent(true); UMConfigure.setProcessEvent(true);
String appKey = call.argument("appKey"); String appKey = call.argument("appKey");
String channel = call.argument("channel"); String channel = call.argument("channel");
boolean enableLog = call.argument("enableLog"); boolean enableLog = call.argument("enableLog");
UMConfigure.preInit(mContext,appKey,channel); UMConfigure.preInit(mContext, appKey, channel);
UMConfigure.setLogEnabled(enableLog); UMConfigure.setLogEnabled(enableLog);
result.success(true); result.success(true);
}else if("init".equals(call.method)){ } else if ("init".equals(call.method)) {
String appKey = call.argument("appKey"); String appKey = call.argument("appKey");
String channel = call.argument("channel"); String channel = call.argument("channel");
Integer deviceType = call.argument("deviceType"); Integer deviceType = call.argument("deviceType");
String pushSecret = call.argument("pushSecret"); String pushSecret = call.argument("pushSecret");
UMConfigure.init(mContext, appKey, channel, deviceType, UMConfigure.init(mContext, appKey, channel, deviceType, pushSecret);
pushSecret);
result.success(true); result.success(true);
}else if("onEvent".equals(call.method)){ } else if ("onEvent".equals(call.method)) {
//UMConfigure.DEVICE_TYPE_PHONE // UMConfigure.DEVICE_TYPE_PHONE
String eventId = call.argument("eventId"); String eventId = call.argument("eventId");
Map<String,Object> properties = call.argument("properties"); Map<String, Object> properties = call.argument("properties");
MobclickAgent.onEventObject(mContext,eventId,properties); MobclickAgent.onEventObject(mContext, eventId, properties);
MobclickAgent.setSessionContinueMillis(1000l); MobclickAgent.setSessionContinueMillis(1000l);
MobclickAgent.setCatchUncaughtExceptions(true); MobclickAgent.setCatchUncaughtExceptions(true);
result.success(true); result.success(true);
}else{ } else {
result.notImplemented(); result.notImplemented();
} }
} }
......
...@@ -20,10 +20,10 @@ class _MyAppState extends State<MyApp> { ...@@ -20,10 +20,10 @@ class _MyAppState extends State<MyApp> {
).then((value) {}).whenComplete(() { ).then((value) {}).whenComplete(() {
Future.delayed(Duration(seconds: 15), () { Future.delayed(Duration(seconds: 15), () {
UmengCommonSdk.init( UmengCommonSdk.init(
'6130b199695f794bbd9cb984', appKey: '6130b199695f794bbd9cb984',
'qiaomeng', channel: 'qiaomeng',
1, deviceType: 1,
'6130b199695f794bbd9cb984', pushSecret: '6130b199695f794bbd9cb984',
); );
}); });
}); });
...@@ -39,12 +39,16 @@ class _MyAppState extends State<MyApp> { ...@@ -39,12 +39,16 @@ class _MyAppState extends State<MyApp> {
children: [ children: [
TextButton( TextButton(
onPressed: () async { onPressed: () async {
await UmengCommonSdk.onEvent('event_test', { await UmengCommonSdk.onEvent(
event: 'event_test',
properties: {
'key': '测试上传数据', 'key': '测试上传数据',
'key1': '测试上传数据', 'key1': '测试上传数据',
});
}, },
child: Text('上报事件')), );
},
child: Text('上报事件'),
),
], ],
), ),
), ),
......
...@@ -7,9 +7,9 @@ class UmengCommonSdk { ...@@ -7,9 +7,9 @@ class UmengCommonSdk {
/// ///
/// 预初始化 /// 预初始化
/// [appKey] /// [appKey] 友盟控制台appKey
/// [channel] /// [channel] app的渠道,如:应用宝、小米、华为应用商店等
/// [enableLog] /// [enableLog] 是否启用日志
/// ///
static Future<bool> preInit({ static Future<bool> preInit({
required String appKey, required String appKey,
...@@ -26,17 +26,17 @@ class UmengCommonSdk { ...@@ -26,17 +26,17 @@ class UmengCommonSdk {
/// ///
/// 初始化 /// 初始化
/// [appKey] AppKey /// [appKey] 友盟控制台appKey
/// [channel] /// [channel] app的渠道,如:应用宝、小米、华为应用商店等
/// [deviceType] /// [deviceType] 设备类型1、手机、2、...
/// [pushSecret] /// [pushSecret] 密钥
/// ///
static Future<bool> init( static Future<bool> init({
String appKey, required String appKey,
String channel, required String channel,
int deviceType, int deviceType = 1,
String pushSecret, String? pushSecret,
) async { }) async {
final dynamic result = await _channel.invokeMethod('init', { final dynamic result = await _channel.invokeMethod('init', {
'appKey': appKey, 'appKey': appKey,
'channel': channel, 'channel': channel,
...@@ -51,8 +51,10 @@ class UmengCommonSdk { ...@@ -51,8 +51,10 @@ class UmengCommonSdk {
/// [event] 事件标志 /// [event] 事件标志
/// [properties] 事件参数 /// [properties] 事件参数
/// ///
static Future<bool> onEvent( static Future<bool> onEvent({
String event, Map<String, dynamic> properties) async { required String event,
required Map<String, dynamic> properties,
}) async {
return await _channel.invokeMethod('onEvent', { return await _channel.invokeMethod('onEvent', {
'eventId': event, 'eventId': event,
'properties': properties, '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