Skip to content

Commit

Permalink
Release 2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
weiqiangliu committed Nov 18, 2022
1 parent 5d740c0 commit 5251614
Show file tree
Hide file tree
Showing 14 changed files with 286 additions and 31 deletions.
4 changes: 1 addition & 3 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## 2.3.0

* 支持 Flutter 项目可视化全埋点及自定义属性

## 2.2.2

* 新增接口 bind、unbind、loginWithKey
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -17,7 +17,7 @@
```yml
dependencies:
# 添加神策 flutter plugin
sensors_analytics_flutter_plugin: ^2.2.2
sensors_analytics_flutter_plugin: ^2.3.0
```

执行 flutter packages get 命令安装插件
Expand Down
5 changes: 3 additions & 2 deletions android/build.gradle
Expand Up @@ -33,6 +33,7 @@ android {
}

dependencies {
api 'com.sensorsdata.analytics.android:SensorsAnalyticsSDK:6.5.4'
//implementation 'org.json:json:20220320'
implementation fileTree(dir: 'libs', include: ['*.jar'])
api 'com.sensorsdata.analytics.android:SensorsAnalyticsSDK:6.6.0'
// implementation 'org.json:json:20220320'
}
@@ -0,0 +1,71 @@
package com.sensorsdata.analytics.sensorsanalyticsflutterplugin;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import com.sensorsdata.analytics.android.sdk.SALog;

import io.flutter.plugin.common.MethodChannel;

public class FlutterVisual {
private static final String TAG = "SA.FlutterVisual";
private final DynamicReceiver mDynamicReceiver;
private MethodChannel mMethodChannel;
private static final String FLUTTER_ACTION = "android.intent.action.FLUTTER_VISUALIZED";
private static final String FLUTTER_EXTRA = "visualizedChanged";
private volatile boolean isRegister = false;
private static volatile FlutterVisual mFlutterVisual;

private FlutterVisual() {
mDynamicReceiver = new DynamicReceiver();
}

public static FlutterVisual getInstance() {
if (mFlutterVisual == null) {
synchronized (FlutterVisual.class) {
if (mFlutterVisual == null) {
mFlutterVisual = new FlutterVisual();
}
}
}
return mFlutterVisual;
}

public void setMethodChannel(MethodChannel methodChannel) {
this.mMethodChannel = methodChannel;
}

class DynamicReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (mMethodChannel != null && intent != null && intent.getStringExtra(FLUTTER_EXTRA) != null) {
if (intent.getStringExtra(FLUTTER_EXTRA).equals("visualizedConnectionStatusChanged")) {
SALog.i(TAG, "visualizedConnectionStatusChanged");
mMethodChannel.invokeMethod("visualizedConnectionStatusChanged", null);
} else if (intent.getStringExtra(FLUTTER_EXTRA).equals("visualizedPropertiesConfigChanged")) {
SALog.i(TAG, "visualizedPropertiesConfigChanged");
mMethodChannel.invokeMethod("visualizedPropertiesConfigChanged", null);
}
}
}
}

public synchronized void registerBroadcast(Context context) {
SALog.i(TAG, "registerBroadcast:" + isRegister);
if (!isRegister) {
SALog.i(TAG, "registerBroadcast");
IntentFilter filter = new IntentFilter();
filter.addAction(FLUTTER_ACTION);
context.registerReceiver(mDynamicReceiver, filter);
isRegister = true;
}
}

public synchronized void unRegisterBroadcast(Context context) {
SALog.i(TAG, "unRegisterBroadcast");
context.unregisterReceiver(mDynamicReceiver);
isRegister = false;
}
}
Expand Up @@ -8,6 +8,8 @@
import com.sensorsdata.analytics.android.sdk.SAConfigOptions;
import com.sensorsdata.analytics.android.sdk.SALog;
import com.sensorsdata.analytics.android.sdk.SensorsDataAPI;
import com.sensorsdata.analytics.android.sdk.core.mediator.Modules;
import com.sensorsdata.analytics.android.sdk.core.mediator.SAModuleManager;
import com.sensorsdata.analytics.android.sdk.plugin.property.SAPropertyPlugin;
import com.sensorsdata.analytics.android.sdk.plugin.property.SAPropertyPluginPriority;
import com.sensorsdata.analytics.android.sdk.plugin.property.beans.SAPropertiesFetcher;
Expand Down Expand Up @@ -44,13 +46,26 @@ public class SensorsAnalyticsFlutterPlugin implements FlutterPlugin, MethodCallH
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "sensors_analytics_flutter_plugin");
channel.setMethodCallHandler(this);
FlutterVisual.getInstance().setMethodChannel(channel);
FlutterVisual.getInstance().registerBroadcast(flutterPluginBinding.getApplicationContext());
}

@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
try {
List list = (List) call.arguments;
switch (call.method) {
case "getVisualizedConnectionStatus":
result.success(SAModuleManager.getInstance().invokeModuleFunction(Modules.Visual.MODULE_NAME, Modules.Visual.METHOD_GET_VISUAL_STATE));
break;
case "sendVisualizedMessage":
String msg = (String) list.get(0);
SAModuleManager.getInstance().invokeModuleFunction(Modules.Visual.MODULE_NAME, Modules.Visual.METHOD_SEND_VISUALIZED_MESSAGE, msg);
result.success(null);
break;
case "getVisualizedPropertiesConfig":
result.success(SAModuleManager.getInstance().invokeModuleFunction(Modules.Visual.MODULE_NAME, Modules.Visual.METHOD_FLUTTER_GET_APPVISUAL_CONFIG));
break;
case "setServerUrl":
setServerUrl(list);
break;
Expand Down Expand Up @@ -201,6 +216,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
channel.setMethodCallHandler(null);
FlutterVisual.getInstance().unRegisterBroadcast(binding.getApplicationContext());
}

private void isNetworkRequestEnable(Result result) {
Expand Down
1 change: 0 additions & 1 deletion example/ios/Podfile
Expand Up @@ -29,7 +29,6 @@ flutter_ios_podfile_setup

target 'Runner' do
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))

end

post_install do |installer|
Expand Down
11 changes: 11 additions & 0 deletions example/ios/Runner/AppDelegate.m
Expand Up @@ -33,4 +33,15 @@ - (BOOL)application:(UIApplication *)application
return [super application:application didFinishLaunchingWithOptions:launchOptions];;
}


- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {

if ([[SensorsAnalyticsSDK sharedInstance] canHandleURL:url]) {
[[SensorsAnalyticsSDK sharedInstance] handleSchemeUrl:url];
}

return NO;
}


@end
13 changes: 13 additions & 0 deletions example/ios/Runner/Info.plist
Expand Up @@ -18,6 +18,19 @@
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>qatest</string>
<key>CFBundleURLSchemes</key>
<array>
<string>sace7b04ba</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
Expand Down
2 changes: 1 addition & 1 deletion example/test/widget_test.dart
Expand Up @@ -8,7 +8,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:sensorsanalyticsflutterplugin_example/main.dart';
import 'package:sensorsanalyticsflutterplugin_example/main_another_entry.dart';

void main() {
testWidgets('Verify Platform version', (WidgetTester tester) async {
Expand Down

0 comments on commit 5251614

Please sign in to comment.