Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
umeng_common_flutter
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
flutter-plugin
umeng_common_flutter
Commits
d65a8692
You need to sign in or sign up before continuing.
Commit
d65a8692
authored
Sep 03, 2021
by
Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新
parent
f81ae31e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
58 deletions
+60
-58
README.md
README.md
+7
-6
android/src/main/java/com/umeng/umeng_common_sdk/UmengCommonSdkPlugin.java
...java/com/umeng/umeng_common_sdk/UmengCommonSdkPlugin.java
+23
-28
example/lib/main.dart
example/lib/main.dart
+13
-9
lib/umeng_common_sdk.dart
lib/umeng_common_sdk.dart
+17
-15
No files found.
README.md
View file @
d65a8692
#
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
android/src/main/java/com/umeng/umeng_common_sdk/UmengCommonSdkPlugin.java
View file @
d65a8692
...
...
@@ -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
(
1000
l
);
MobclickAgent
.
setCatchUncaughtExceptions
(
true
);
result
.
success
(
true
);
}
else
{
}
else
{
result
.
notImplemented
();
}
}
...
...
example/lib/main.dart
View file @
d65a8692
...
...
@@ -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
(
'上报事件'
),
),
],
),
),
...
...
lib/umeng_common_sdk.dart
View file @
d65a8692
...
...
@@ -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]
A
ppKey
/// [channel]
/// [deviceType]
/// [pushSecret]
/// [appKey]
友盟控制台a
ppKey
/// [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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment