Open Contacts on device via icon tap flutter

笑着哭i 提交于 2021-01-28 21:47:05

问题


Is it possible to open the contacts on a device from an icon tap in flutter? I am able to open the phone function using url_launcher's plugin.I have used the contacts plugin but we dont have a need to manage contacts from our application, we want to use the phones functionality for managing contacts.


回答1:


You can achieve this using Flutter platform channels and android Intent.ACTION_VIEW intent.

For example in your MainActivity register new channel and launch Contacts activity:

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

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

And on flutter side:

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

Please see full example. Hope this help.




回答2:


Probably you can't directly.

But you can fetch them and their info with contacts_service package.

Hope this could help you.



来源:https://stackoverflow.com/questions/58864197/open-contacts-on-device-via-icon-tap-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!