morenoh149 / react-native-contacts

React Native Contacts
MIT License
1.65k stars 564 forks source link

Crash on Android when loading contacts #596

Closed IbrahimCanKALYA closed 3 years ago

IbrahimCanKALYA commented 3 years ago

Couldn't read row 900, col 1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it. com.rt2zz.reactnativecontacts.ContactsProvider.loadContactsFrom

Device Info: Brand: Xiaomi Model: Mi A1 Operating System Version: 9 Rooted: No

react-native: 0.62.2 react-native-contacts: 6.0.4

I faced with this crash & i couldn't find any solution or wrong usage of library.

thanks in advance

gabrieloureiro commented 3 years ago

me too

gabrieloureiro commented 3 years ago

I managed to fix this problem.

import React, { useEffect, useState } from 'react'`
> `import Contacts from 'react-native-contacts';`
> `import { PermissionsAndroid } from 'react-native';`
> 
> ...
> ` const [contacts, setContacts] = useState<any>([])`
> 
> `async function hasAndroidPermission() {`
>     `const permission = PermissionsAndroid.PERMISSIONS.READ_CONTACTS;`
>     `const hasPermission = await PermissionsAndroid.check(permission);`
>    ` if (hasPermission) {`
>       `return true;`
>     `}`
>     `const status = await PermissionsAndroid.request(permission);`
>     `return status === 'granted';`
>  ` }`
> 
>   `const loadContacts = async () => {`
>    ` if (await hasAndroidPermission()) {`
>       `Contacts.getAll().then(contacts => {`
>        ` setContacts(contacts)`
>       `})`
>     `}`
>     `return`
>   `};`
> 
>  `useEffect(() => {`
>     `hasAndroidPermission()`
>   `}, [])`
> 
>   `useEffect(() => {`
>    ` loadContacts()`
>   `}, [hasAndroidPermission])`
mayank-budhiraja commented 3 years ago

Hello! anyone raising PR for this?

morenoh149 commented 3 years ago

nope. @mayank-budhiraja would you like to write the PR?

github-actions[bot] commented 3 years ago

This issue is stale, please provide more information about the status

morenoh149 commented 3 years ago

@gabrieloureiro what is the issue?

abhishekchotaliya commented 2 years ago

Faced similar issue. When trying to get the contacts using the provided example, the app was crashing as soon as I request for the permission.

After countless hours of findings, this was the only answer which helped, (app got crashed after allowing the read permission, but didn't crash after) https://github.com/morenoh149/react-native-contacts/issues/549#issuecomment-691893482