×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    78

    Question How to add new Contact?

    Hello Friends,
    I want to add New contact which contain only Two fields ForeName and PhonenUmber into the ContactDatabaseI already tried this but i got System Error(-23).
    Here is my Code
    Code:
    void CCellLogsAppView::AddOwnContact()
        {
    		_LIT(KForenameLabel,"Forename");
    		_LIT(KWorkPhoneLabel,"Work Phone");
    		_LIT(KForename,"Own");
    		// Open the default contacts database:
    		CContactDatabase* contactsDb = CContactDatabase::OpenL();
    		CleanupStack::PushL(contactsDb);
    		
    		// Create a contact card and add some fields:
    		CContactItem* contact = CContactCard::NewLC();
    		//Create & Add Forename
    		CContactItemField* field = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldGivenName);
    		field->SetMapping(KUidContactFieldVCardMapUnusedN);
    		field->SetLabelL(KForenameLabel);
    		field->TextStorage()->SetTextL(KForename);
    		contact->AddFieldL(*field);
    		CleanupStack::Pop();
    		
    		//Create & Add Phone Number
    		field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldPhoneNumber);
    		field->SetMapping(KUidContactFieldVCardMapTEL);
    		field->SetLabelL(KWorkPhoneLabel);
    		field->TextStorage()->SetTextL(*ownNumber); //OwnNumber is HBufC* which Contain Phone Number
    		contact->AddFieldL(*field);
    		CleanupStack::Pop();
    		
    		// Add the new contact to the database and set it as the own card:
    		contactsDb->AddNewContactL(*contact); //I got System Error (-23)on this line.
    		contactsDb->SetOwnCardL(*contact);
    		 
    		CleanupStack::PopAndDestroy(2); // contact contactsDb
        
        }
    Can anybody tell me what's the problem?

    Thanks & Regards
    Ankit Nigam

  2. #2
    Regular Contributor
    Join Date
    Jul 2009
    Posts
    211

    Re: How to add new Contact?

    contactsDb->SetOwnCardL(*contact); is not necessary to add new contact.That is to set the data as owner details.
    and i thnk pbm is on your own number..
    Try something like

    _LIT(KPhone,"9999999999");

    field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldPhoneNumberValue);
    field->SetMapping(KUidContactFieldVCardMapTEL);
    field->TextStorage()->SetTextL(KPhone);
    contact->AddFieldL(*field);
    CleanupStack::Pop();

  3. #3
    Regular Contributor
    Join Date
    Jul 2009
    Posts
    211

    Question How to add new Contact?

    contactsDb->SetOwnCardL(*contact); is not necessary to add new contact.That is to set the data as owner details.
    and i thnk pbm is on your own number..
    Try something like

    _LIT(KPhone,"9999999999");

    field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldPhoneNumberValue);
    field->SetMapping(KUidContactFieldVCardMapTEL);
    field->TextStorage()->SetTextL(KPhone);
    contact->AddFieldL(*field);
    CleanupStack::Pop();

  4. #4
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    78

    Question Re: How to add new Contact?

    Hi Siva,
    I also tried this code but it also give me same error :
    Code:
                    _LIT(KForenameLabel,"Forename");
    		_LIT(KForename,"Own");
    			
    		// Open the default contacts database:
    		CContactDatabase* contactsDb = CContactDatabase::OpenL();
    		CleanupStack::PushL(contactsDb);
    		
    		// Create a contact card and add some fields:
    		CContactItem* contact = CContactCard::NewLC();
    		//Create & Add Forename
    		CContactItemField* field = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldGivenName);
    		field->SetMapping(KUidContactFieldVCardMapUnusedN);
    		field->SetLabelL(KForenameLabel);
    		field->TextStorage()->SetTextL(KForename);
    		contact->AddFieldL(*field);
    		CleanupStack::Pop();
    		
    
    		 
    		// Add the new contact to the database and set it as the own card:
    		contactsDb->AddNewContactL(*contact);
    				 
    		CleanupStack::PopAndDestroy(2); // contact contactsDb

  5. #5
    Regular Contributor
    Join Date
    Jul 2009
    Posts
    211

    Re: How to add new Contact?

    Where are you calling this method AddOwnContact()?

  6. #6
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    78

    Question Re: How to add new Contact?

    Quote Originally Posted by siva_321 View Post
    Where are you calling this method AddOwnContact()?
    Actually My requirement is like this :
    1. First i will call CheckOwnNumber function from ConstructL before SetRect(aRect).
    2. In CheckOwnNumber i will check Contact Database for Own Number if it present i will return ETrue and if not it return EFalse.
    3. Then if Number is not Present i will show Numeric Query Dialog and then enter number and press Ok and on Ok i will Call AddOwnContact().

  7. #7
    Regular Contributor
    Join Date
    Jul 2009
    Posts
    211

    Re: How to add new Contact?

    First Call AddOwnContact() in constructL before Setrect() and run default Contacts app in the emulator and check whether the contact is added into the database or not?

  8. #8
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    78

    Question Re: How to add new Contact?

    Quote Originally Posted by siva_321 View Post
    First Call AddOwnContact() in constructL before Setrect() and run default Contacts app in the emulator and check whether the contact is added into the database or not?
    Hi Siva,
    I tried this,i first called AddOwnContact() in ConstructL but it will give me same error on same place means
    contactsDb->AddNewContactL(*contact);

  9. #9
    Regular Contributor
    Join Date
    Jul 2009
    Posts
    211

    Re: How to add new Contact?


  10. #10
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    78

    Question Re: How to add new Contact?

    Quote Originally Posted by siva_321 View Post
    Hi Siva,
    I already check that link i have also added WriteUserData capability into my .mmp file but problem is same.Can you have any other solutions?

  11. #11
    Regular Contributor
    Join Date
    Jul 2009
    Posts
    211

    Re: How to add new Contact?

    I am doing what you have done.It is working fine.

    Put debug points and check whether you are opening default database(contacts.cdb).

  12. #12
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    78

    Re: How to add new Contact?

    Hi,
    Siva can you send me your code what you are doing. I wan to know where am i wrong.

  13. #13
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    78

    Question Re: How to add new Contact?

    Quote Originally Posted by siva_321 View Post
    I am doing what you have done.It is working fine.

    Put debug points and check whether you are opening default database(contacts.cdb).
    Hi Siva,
    Now i checked where i open Default Contact Database and i found that i tried to Open Default Contact database second time i already opened Database previously and i agained opened it inot AddOwnContact(). Now I used previous instance of Database but now also i got Panic KERN-EXEC 3 at the same line.
    iContactDb->AddNewContactL(*contact);

  14. #14
    Regular Contributor
    Join Date
    Jul 2009
    Posts
    211

    Re: How to add new Contact?

    void CContactAddAppView::ConstructL(const TRect& aRect)
    {
    // Create a window for this application view
    CreateWindowL();
    insertdata();
    // Set the windows size
    SetRect(aRect);

    // Activate the window, which makes it ready to be drawn
    ActivateL();
    }


    void CContactAddAppView::insertdata()
    {
    // _LIT(KForenameLabel,"Forename");
    // _LIT(KSurnameLabel,"Surname");
    // _LIT(KWorkPhoneLabel,"Work Phone");
    _LIT(KForename,"Sambo");
    _LIT(KSurname,"siva");
    _LIT(KWorkPhone,"9999999999");


    CContactDatabase* contactsDb = CContactDatabase::OpenL();
    CleanupStack::PushL(contactsDb);


    CContactItem* contact = CContactCard::NewLC();
    CContactItemField* field = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldFamilyName);
    field->SetMapping(KUidContactFieldVCardMapUnusedN);
    //field->SetLabelL(KSurnameLabel);
    field->TextStorage()->SetTextL(KSurname);
    contact->AddFieldL(*field);
    CleanupStack::Pop();


    field = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldGivenName);
    field->SetMapping(KUidContactFieldVCardMapUnusedN);
    //field->SetLabelL(KForenameLabel);
    field->TextStorage()->SetTextL(KForename);
    contact->AddFieldL(*field);
    CleanupStack::Pop();

    field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldPhoneNumberValue);
    field->SetMapping(KUidContactFieldVCardMapTEL);
    //field->SetLabelL(KWorkPhoneLabel);
    field->TextStorage()->SetTextL(KWorkPhone);
    contact->AddFieldL(*field);
    CleanupStack::Pop();

    contactsDb->AddNewContactL(*contact);



    CleanupStack::PopAndDestroy(2);

    }

  15. #15
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    78

    Re: How to add new Contact?

    this code give error on this line
    field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldPhoneNumberValue);

Similar Threads

  1. Add contact on installation and remove on uninstallation
    By swapnil_mahajan in forum Symbian
    Replies: 1
    Last Post: 2009-08-21, 14:41
  2. add contact from contact list
    By gopikishan in forum General Development Questions
    Replies: 1
    Last Post: 2009-04-21, 16:41
  3. Replies: 3
    Last Post: 2007-12-06, 12:55
  4. can't add new contact item to a group
    By zikman9 in forum Symbian
    Replies: 6
    Last Post: 2006-07-24, 07:50
  5. add new contact problem
    By zikman9 in forum Symbian
    Replies: 7
    Last Post: 2003-11-29, 10:57

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×