问题
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