Skip to content

flutter call android always throw MissingPluginException(No implementation found for method getDeviceInfo #83210

@Reinoal

Description

@Reinoal

what did I do wrong? All dependencies are added.
I've tried many things, and the result is always the same.

[ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: MissingPluginException(No implementation found for method getDeviceInfo on channel faxian.com/device_info)
E/flutter (22021): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:7)
E/flutter (22021): <asynchronous suspension>
E/flutter (22021): #1      _LoginPageState._getDeviceInfo (package:flutter_faxian/pages/login/index.dart:84:20)
E/flutter (22021): <asynchronous suspension>
android 11
Framework • revision adc687823a (5 weeks ago) • 2021-04-16 09:40:20 -0700
Engine • revision b09f014e96
Tools • Dart 2.12.3
const info_Channel = const MethodChannel("faxian.com/device_info");

void _getDeviceInfo()async{
    final result = await info_Channel.invokeMethod("getDeviceInfo");
    print(result);
  }
<meta-data
                android:name="io.flutter.embedding.android.NormalTheme"
                android:resource="@style/NormalTheme"
                tools:replace="android:resource" />
<meta-data
                android:name="io.flutter.embedding.android.SplashScreenDrawable"
                android:resource="@drawable/launch_background" />
<meta-data
            android:name="flutterEmbedding"
            android:value="2" />
import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
class MainActivity: FlutterActivity() {

    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
        flutterEngine.plugins.add(GetDevicePlugin())
        super.configureFlutterEngine(flutterEngine)
    }
}

class GetDevicePlugin:FlutterActivity(), FlutterPlugin, MethodChannel.MethodCallHandler{

    private val CHANNEL = "faxian.com/device_info"

    override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
        if (call.method.equals("getDeviceInfo")){
            result.success("------flutter call android getDeviceInfo------")
        }
    }

    override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
        val channel = MethodChannel(binding.binaryMessenger, CHANNEL)
        channel.setMethodCallHandler(this)
    }

    override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
    }
}
[✓] Flutter (Channel stable, 2.0.5, on macOS 11.2.3 20D91 darwin-x64, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.2)
[✓] VS Code (version 1.56.2)
[✓] Connected device (2 available)

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: invalidIssue is closed as not valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions