Pārlūkot izejas kodu

添加安卓moblink

tags/0.0.2+9^0
Weller pirms 4 gadiem
vecāks
revīzija
d87f846d67
4 mainītis faili ar 83 papildinājumiem un 44 dzēšanām
  1. +1
    -1
      example/android/app/src/main/AndroidManifest.xml
  2. +25
    -19
      example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java
  3. +16
    -0
      example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MyFlutterApplication.java
  4. +41
    -24
      lib/pages/home_page/home_page.dart

+ 1
- 1
example/android/app/src/main/AndroidManifest.xml Parādīt failu

@@ -25,7 +25,7 @@
<uses-feature android:name="android.hardware.camera.autofocus" />

<application
android:name="io.flutter.app.FlutterApplication"
android:name="cn.zhios.zhiying_base_widget_example.MyFlutterApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:allowBackup="true"


+ 25
- 19
example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java Parādīt failu

@@ -10,6 +10,9 @@ import android.view.WindowManager;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.moblink.MoblinkPlugin;
import com.mob.moblink.MobLink;

import java.util.HashMap;
import java.util.Map;

@@ -30,6 +33,9 @@ public class MainActivity extends FlutterActivity implements ZhiyingFlutterCommN
super.onCreate(savedInstanceState);
configureWindowForTransparency();
configureStatusBarForFullscreenFlutterExperience();

MobLink.setRestoreSceneListener(new MoblinkPlugin.SceneListener());

}

@Override
@@ -71,25 +77,25 @@ public class MainActivity extends FlutterActivity implements ZhiyingFlutterCommN

}

@Override
public Map getSetting() {
Map map = new HashMap();
map.put("domain", "http://inapi.izhyin.cn"); //"http://120.76.175.204:8989");
@Override
public Map getSetting() {
Map map = new HashMap();
map.put("domain", "http://inapi.izhyin.cn"); //"http://120.76.175.204:8989");
// map.put("domain", "http://192.168.0.113:5000");
map.put("master_id", "123456");
map.put("secret_key", "123456");
map.put("master_id", "123456");
map.put("secret_key", "123456");
// map.put("token", "123465");
return map;
}
@Override
public void invokeMethod(String method, Map<String, Object> params, ZhiyingFlutterCommHandler handler) {
return;
}
@Override
protected void onDestroy() {
super.onDestroy();
ZhiyingFlutterCommNative.getInstance().unregist();
}
return map;
}
@Override
public void invokeMethod(String method, Map<String, Object> params, ZhiyingFlutterCommHandler handler) {
return;
}
@Override
protected void onDestroy() {
super.onDestroy();
ZhiyingFlutterCommNative.getInstance().unregist();
}
}

+ 16
- 0
example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MyFlutterApplication.java Parādīt failu

@@ -0,0 +1,16 @@
package cn.zhios.zhiying_base_widget_example;

import com.example.moblink.MoblinkPlugin;
import com.mob.moblink.MobLink;

import io.flutter.app.FlutterApplication;

public class MyFlutterApplication extends FlutterApplication {

//防止MobLink在APP杀死进程后无法还原
@Override
public void onCreate() {
super.onCreate();
MobLink.setRestoreSceneListener(new MoblinkPlugin.SceneListener());
}
}

+ 41
- 24
lib/pages/home_page/home_page.dart Parādīt failu

@@ -65,27 +65,6 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
super.initState();
}

// 场景还原,记录邀请码
void _restore(MLSDKScene scene) {
const bool inProduction = const bool.fromEnvironment("dart.vm.product");
if (!inProduction) {
// 非release环境,弹窗测试
showAlert('要还原的路径为:' + scene.className + '\n' + scene.params.toString(),
context);
}
Logger.debug('要还原的路径为:' + scene.className);
try {
Map<String, dynamic> params = Map<String, dynamic>.from(scene.params);
if (params.containsKey('tgid')) {
String tgid = params['tgid'].toString();
// 记录邀请码到本地
SharedPreferencesUtil.setNetCacheResult(Constants.mobInvitedCode, tgid);
}
} catch (e) {
Logger.debug(e);
}
}

@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
@@ -222,16 +201,54 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
IntellectCreate.checkAndCreateFirst(context);
}

// 场景还原,记录邀请码
void _restore(MLSDKScene scene) {
// const bool inProduction = const bool.fromEnvironment("dart.vm.product");
bool inProduction = false;
if (!inProduction) {
// 非release环境,弹窗测试
showAlert('要还原的路径为:' + scene.className + '\n' + scene.params.toString(),
context);
}
Logger.debug('要还原的路径为:' + scene.className);
try {
Map<String, dynamic> params = Map<String, dynamic>.from(scene.params);
if (params.containsKey('tgid')) {
String tgid = params['tgid'].toString();
// 记录邀请码到本地
SharedPreferencesUtil.setNetCacheResult(Constants.mobInvitedCode, tgid);
}
} catch (e) {
Logger.error(e);
}
}

//app存在后台时候的还原
void _onEvent(Object event) {
Logger.debug('返回的内容: $event');
if (null != event) {
showAlert('要还原的路径为[活着]:$event', context);
try {
if (null != event) {
Map<String, dynamic> params = Map<String, dynamic>.from(event);
// const bool inProduction = const bool.fromEnvironment("dart.vm.product");
bool inProduction = false;
if (!inProduction) {
// 非release环境,弹窗测试
showAlert('要还原的路径为[活着]:$event', context);
}
if (params['params'].containsKey('tgid')) {
String tgid = params['params']['tgid'].toString();
// 记录邀请码到本地
SharedPreferencesUtil.setNetCacheResult(
Constants.mobInvitedCode, tgid);
}
}
} catch (e) {
Logger.error(e);
}
}

void _onError(Object error) {
Logger.debug('返回的错误');
Logger.error('返回的错误: $error');
}

void showAlert(String text, BuildContext context) {


Notiek ielāde…
Atcelt
Saglabāt