Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add Group in React Native Android ? #97

Open
lynshashank opened this issue Aug 21, 2020 · 2 comments
Open

How to add Group in React Native Android ? #97

lynshashank opened this issue Aug 21, 2020 · 2 comments

Comments

@lynshashank
Copy link

Hey while writing code for add group it is giving undefined error and not working . I have the group data in my code but group is not making provide and an error ? Please help !

@morenoh149
Copy link

share code. But I'm not sure its possible.

@lynshashank
Copy link
Author

share code. But I'm not sure its possible.

I am having the same code as author .
ort default class App extends Component {

constructor( props ) {
super( props );

const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});

//this.state = {} //call states
this.startListenerTapped = this.startListenerTapped.bind(this);
this.state = {
  canUserAccessContact: null,
  contacts:  [],
  callStates : [], ds: ds
};

this._checkIfUserCanAccessContacts();
this._checkIfAlreadyRequestedAccessToContacts();

}
startListenerTapped() {
callDetector = new CallDetectorManager((event, number) => {
var updatedCallStates = this.state.callStates
updatedCallStates.push(event + ' - ' + number)
var previousDS = this.state.ds
this.setState({ callStates: updatedCallStates, ds: previousDS.cloneWithRows(updatedCallStates)});
},
false, // if you want to read the phone number of the incoming call [ANDROID], otherwise false
()=>{}, // callback if your permission got denied [ANDROID] [only if you want to read incoming number] default: console.error
{
title: 'Phone State Permission',
message: 'This app needs access to your phone state in order to react and/or to adapt to incoming calls.'
} // a custom permission request message to explain to your user, why you need the permission [recommended] - this is the default one
)
}

callFriendTapped() {
Linking.openURL('tel:5555555555')
.catch(err => {
console.log(err)
});
}

stopListenerTapped() {
callDetector && callDetector.dispose();
}

render() {
let badgeColor;
if ( this.state.canUserAccessContacts ) {
badgeColor = "#44B240";
}
else {
badgeColor = "#FF838A";
}

let alreadyRequestedBadgeColor;
if ( this.state.alreadyRequestedAccessToContacts ) {
  alreadyRequestedBadgeColor = "#44B240";
}
else {
  alreadyRequestedBadgeColor = "#FF838A";
}

// let groupData = {
//   'name': 'Friends',
//   'name': 'Irritating',
//   'name': 'Family',
//   'name': 'Close Friends'
// }

// Contacts.addGroup(groupData, (error, success) => {
//   if (this.state.addGroup) {
//     console.log(error);
//   }
//   else {
//     console.log(success);
//   }
// });

return (
  <ScrollView style={ styles.scrollView }>
    <View style={ styles.container }>
      <Text style={ styles.welcome }>
        WORK MODE
      </Text>

      <View style={ [ styles.badge, { backgroundColor: badgeColor } ] }>
        <Text style={ { color: "white" } }>{ this.state.canUserAccessContacts ? "ACCESS GRANTED" : "ACCESS DENIED" }</Text>
      </View>

      <View style={ [ styles.badge, { backgroundColor: alreadyRequestedBadgeColor } ] }>
        <Text style={ { color: "white" } }>{ this.state.alreadyRequestedAccessToContacts ? "ALREADY REQUESTED" : "NEVER REQUESTED" }</Text>
      </View>

{/*
<View style={ [ styles.badge, { backgroundColor: groupData } ] }>
<Text style={ { color: "white" } }>{ this.state.groupData ? "GROUP DATA ADDED" : "NOT ADDED" }
*/}

      <View style={ styles.button }>
        <Button title="Request Access to Contacts" onPress={ () => this._requestAccessToContacts() } />
      </View>

      <View style={ styles.button }>
        <Button title="Open Privacy Settings" onPress={ () => this._openPrivacySettings() } />
      </View>

      <View style={ styles.button }>
        <Button title="Get Contacts" onPress={ () => this._getContacts() } />
      </View>

      <View style={ styles.button }>
        <Button title="Select Contact" onPress={ () => this._selectContact() } />
      </View>

      {/* <View style={ styles.button}>
         <Button title="Add Group" onPress={ () => this._addGroup()}/>
      </View> */}

      <View style={ styles.button }>
        <TextInput value={ this.state.searchText } onChangeText={ text => this.setState( { searchText: text } ) } />
        <Button title="Search Name in Contacts" onPress={ () => this._searchContacts( this.state.searchText ) } />
      </View>

      <View style={styles.container}>
    <Button
      onPress={this.startListenerTapped}
      title="Start Listener"
      color="#841584"
      style = {styles.bottomMargin}
    />

    <Button
      onPress={this.callFriendTapped}
      title="Call your friend"
      color="#341584"
      style = {styles.bottomMargin}
    />
    <Button
      onPress={this.stopListenerTapped}
      title="Stop Listener"
      color="#841584"
      style = {styles.bottomMargin}
    />

    <Text style = {styles.text}>
      Call State Logs
    </Text>

    <FlatList
      dataSource={this.state.ds}
      renderRow={(rowData) => <Text style = {styles.callLogs}>{rowData}</Text>}
    />
  </View>

      <FlatList
        style={ styles.contacts }
        data={ this.state.contacts }
        keyExtractor={ contact => contact.identifier }
        renderItem={ ( { item } ) => (
          <View style={ styles.contact }>
            <Text style={ styles.name }>
              { item.fullName }
            </Text>
          </View>
        ) }
      />

    </View>
  </ScrollView>
    
);

}

_checkIfUserCanAccessContacts() {
Contacts.userCanAccessContacts( canUserAccessContacts => {
this.setState( { canUserAccessContacts } );
} );
}

_checkIfAlreadyRequestedAccessToContacts() {
Contacts.alreadyRequestedAccessToContacts( alreadyRequestedAccessToContacts => {
this.setState( { alreadyRequestedAccessToContacts } );
} );
}

_requestAccessToContacts() {
Contacts.requestAccessToContacts( canUserAccessContacts => {
this.setState( {
canUserAccessContacts,
alreadyRequestedAccessToContacts: true
} );
} );
}

// _addGroup() {
// Contacts.addGroup( groupData , (error , success)=> {
// if(error){
// console.log(error);
// }
// else{
// this.setState( { groupData } );
// }
// });
// }

_openPrivacySettings() {
Contacts.openPrivacySettings();
}

_getContacts() {
if ( !this.state.canUserAccessContacts ) return;

Contacts.getContacts( ( error, contacts ) =>  {
  if ( error ) {
    console.error( error );
  }
  else {
    this.setState( { contacts } );
  }
} );

}

_selectContact() {
Contacts.selectContact( ( error, contact ) => {
if ( error ) {
console.error( error );
}
else {
const contacts = [ contact ];
this.setState( { contacts } );
}
} );
}
// _addContact(){
// Contacts.addContact(groupData, (error, success) => {
// if( error ){
// console.error( error );
// }
// else{
// const contacts = [contact];
// this.setState( {contacts} );
// }

// });

// }

// _selectContact() {
// if (this.state.canUserAccessContacts) {
// Contacts.selectContact( (error, contact) => {
// if (error) {
// console.error(error);
// }
// else {
// this.setState( { contacts: [ contact ] } );
// }
// });
// }
// }

// _addContact() {
// if (this.state.canUserAccessContacts) {
// Contacts.addContact( (error, contact) => {
// if (error) {
// console.error(error);
// }
// else {
// this.setState( { contacts: [ contact ] } );
// }
// });
// }
// }

// _addGroup( searchText ) {
// if ( this.state.canUserAccessContacts ) {
// Contacts.addGroup( searchText, ( error, contacts ) => {
// if ( error ) {
// console.error( error );
// }
// else {
// this.setState( { contacts: [ contact ] } );
// }
// });

// }

// }

_searchContacts( searchText ) {
if ( this.state.canUserAccessContacts ) {
Contacts.searchContacts( searchText, ( error, contacts ) => {
if ( error ) {
console.error( error );
}
else {
this.setState( { contacts } );
}
} );
}
I have commented some line which previously used .

@lynshashank lynshashank changed the title How to add Group in Android ? How to add Group in React Native Android ? Aug 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants