added fetch contact from real device icon
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { PermissionsAndroid, Platform, NativeModules } from "react-native";
|
||||
|
||||
const { ContactsModule } = NativeModules;
|
||||
|
||||
async function fetchContacts() {
|
||||
if (Platform.OS === "android") {
|
||||
const granted = await PermissionsAndroid.request(
|
||||
PermissionsAndroid.PERMISSIONS.READ_CONTACTS,
|
||||
{
|
||||
title: "Contacts Permission",
|
||||
message: "This app would like to view your contacts.",
|
||||
buttonPositive: "OK",
|
||||
}
|
||||
);
|
||||
|
||||
if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
|
||||
console.log("Contacts permission denied");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const contacts = await ContactsModule.getContacts();
|
||||
console.log("Contacts:", contacts);
|
||||
} catch (error) {
|
||||
console.error("Error fetching contacts:", error);
|
||||
}
|
||||
}
|
||||
export { fetchContacts };
|
||||
Reference in New Issue
Block a user