<activityandroid:name=".MainActivity"android:exported="true"android:launchMode="singleTop"android:theme="@style/LaunchTheme"android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"android:hardwareAccelerated="true"android:windowSoftInputMode="adjustResize"><!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. --><meta-dataandroid:name="io.flutter.embedding.android.NormalTheme"android:resource="@style/NormalTheme"/><intent-filter><actionandroid:name="android.intent.action.MAIN"/><categoryandroid:name="android.intent.category.LAUNCHER"/><!-- 添加如下代码 --><categoryandroid:name="android.intent.category.DEFAULT"/></intent-filter></activity>
1.2 在Android源代码的mainActivity为如下代码
package com.swan.flutter_framework
import android.os.Bundle
import io.flutter.plugin.common.MethodChannel
import io.flutter.embedding.android.FlutterActivity
class MainActivity :FlutterActivity(){overridefunonCreate(savedInstanceState: Bundle?){//FlutterMain.startInitialization(this);super.onCreate(savedInstanceState)// GeneratedPluginRegistrant.registerWith(FlutterEngine(this)) // here is the error: Type mismatch. Required: FlutterEngine! Found: MainActivity//接收第三方app调运参数并且传递给flutterMethodChannel(flutterEngine?.dartExecutor, CHANNEL).setMethodCallHandler{ call, result ->if(call.method == InvokeMethod){val greetings =successNativeCode()
result.success(greetings)}}}privatefunsuccessNativeCode(): String {return"我是android原生跑过来的数据=>${intent.getStringExtra("test")}"}companionobject{privateconstval CHANNEL ="com.swan.shareData"privateconstval InvokeMethod ="shareData"}}