Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 尝试在现有颤振应用程序中实现颤振触点示例_Android_Kotlin_Flutter_Dart - Fatal编程技术网

Android 尝试在现有颤振应用程序中实现颤振触点示例

Android 尝试在现有颤振应用程序中实现颤振触点示例,android,kotlin,flutter,dart,Android,Kotlin,Flutter,Dart,我正在尝试实现这里的flatter_contacts示例:在我现有的flatter应用程序中,但是我在调用kotlin方法时遇到了问题。据我所知,我已经完全镜像了这个功能,但是当我调用launchcontacts方法时,它抛出了一个缺少插件的异常。以下是错误: E/flutter (10095): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: MissingPluginException(No implemen

我正在尝试实现这里的flatter_contacts示例:在我现有的flatter应用程序中,但是我在调用kotlin方法时遇到了问题。据我所知,我已经完全镜像了这个功能,但是当我调用launchcontacts方法时,它抛出了一个缺少插件的异常。以下是错误:

E/flutter (10095): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: MissingPluginException(No implementation found for method launch on channel flutter_contacts/launch_contacts)
当我运行expmle应用程序时,它在expmle应用程序中运行良好,因此我假设我遗漏了一些东西

主要活动代码:

 package com.lightbridge.flutter_contacts

 import android.app.Activity
 import android.content.Intent
 import android.os.Bundle
 import android.provider.ContactsContract
 import io.flutter.app.FlutterActivity
 import io.flutter.plugin.common.MethodChannel
 import io.flutter.plugins.GeneratedPluginRegistrant

 class MainActivity : FlutterActivity() {

var lastResult: MethodChannel.Result? = null

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    GeneratedPluginRegistrant.registerWith(this)

    MethodChannel(flutterView, CHANNEL).setMethodCallHandler { call, result ->
        lastResult = result
        launchContactActivity()
    }
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    if (requestCode == REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            lastResult?.success("Done!")
        } else {
            lastResult?.error("Error", "Can't launch contacts", "")
        }
    }
}

private fun launchContactActivity() {
    val intent = Intent(Intent.ACTION_VIEW)
    intent.type = ContactsContract.Contacts.CONTENT_TYPE
    startActivityForResult(intent, REQUEST_CODE)
}

companion object {
    private const val CHANNEL = "flutter_contacts/launch_contacts"
    private const val REQUEST_CODE = 42
}
 }
要启动的Dart代码

   void launchContacts() async {
   try {
    await platform.invokeMethod('launch');
   } on PlatformException catch (e) {
    print("Failed to launch contacts: ${e.message}");
   }
  setState(() {
  });
 }

setMethodCallHandler中,必须编写一条if语句来检查方法名称,然后执行它:

if (call.method == "launch")
     launchContactActivity()