gpt4 book ai didi

flutter - 在 flutter 中获取联系人

转载 作者:行者123 更新时间:2023-12-03 02:47:34 26 4
gpt4 key购买 nike

我正在尝试使用“contacts_service”插件从设备设备获取联系人。它在我的设备上运行良好,但无法在任何其他设备上运行。

    await PermissionHandler().requestPermissions([
PermissionGroup.contacts,
]);
try {
var x = await ContactsService.getContacts();
print(x);
} catch (e) {
print(e);
}

这是我收到的错误信息

FATAL EXCEPTION: AsyncTask #2
E/AndroidRuntime(17213): Process: com.chat.amrirez_chat, PID: 17213
E/AndroidRuntime(17213): java.lang.RuntimeException: An error occurred while executing doInBackground()
E/AndroidRuntime(17213): at android.os.AsyncTask$3.done(AsyncTask.java:318)
E/AndroidRuntime(17213): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
E/AndroidRuntime(17213): at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
E/AndroidRuntime(17213): at java.util.concurrent.FutureTask.run(FutureTask.java:242)
E/AndroidRuntime(17213): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
E/AndroidRuntime(17213): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
E/AndroidRuntime(17213): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
E/AndroidRuntime(17213): at java.lang.Thread.run(Thread.java:761)
E/AndroidRuntime(17213): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.toLowerCase()' on a null object reference
E/AndroidRuntime(17213): at flutter.plugins.contactsservice.contactsservice.Contact.compareTo(Contact.java:94)
E/AndroidRuntime(17213): at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin$GetContactsTask$1.compare(ContactsServicePlugin.java:175)
E/AndroidRuntime(17213): at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin$GetContactsTask$1.compare(ContactsServicePlugin.java:172)
E/AndroidRuntime(17213): at java.util.TimSort.binarySort(TimSort.java:292)
E/AndroidRuntime(17213): at java.util.TimSort.sort(TimSort.java:235)
E/AndroidRuntime(17213): at java.util.Arrays.sort(Arrays.java:1523)
E/AndroidRuntime(17213): at java.util.Collections.sort(Collections.java:238)
E/AndroidRuntime(17213): at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin$GetContactsTask.doInBackground(ContactsServicePlugin.java:178)
E/AndroidRuntime(17213): at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin$GetContactsTask.doInBackground(ContactsServicePlugin.java:137)
E/AndroidRuntime(17213): at android.os.AsyncTask$2.call(AsyncTask.java:304)
E/AndroidRuntime(17213): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
E/AndroidRuntime(17213): ... 4 more

最佳答案

给ManifestFiles添加权限(flutter Project中有两个Manifest.xml)

主/AndroidManifest.xml

<uses-permission android:name="android.permission.READ_CONTACTS" />  
<uses-permission android:name="android.permission.WRITE_CONTACTS" />

使用包:联系人服务0.3.3

https://pub.dev/packages/contacts_service

关于flutter - 在 flutter 中获取联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57921348/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com