Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old August 23rd, 2010, 08:04 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Aug 2010
Posts: 6
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb adding and deleting contact by code

hi,
to display the contact i have used this coding
Code:
Cursor cursor = getContacts(); String[] fields = new String[] { ContactsContract.Data.DISPLAY_NAME }; //this.setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_checked,));
SimpleCursorAdapter adapter =
new SimpleCursorAdapter(this, android.R.layout.simple_list_item_checked, cursor, fields,
newint[] { R.id.contactEntryText });
mContactList.setAdapter(adapter);
exception is thrown, i got successful in textview but i want it in listview(scrollable)

to add the contact, i have used the code
Code:
ArrayList<ContentProviderOperation> ops =
new ArrayList<ContentProviderOperation>();
ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI) .withValue(Data.RAW_CONTACT_ID,0) .withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE) .withValue(Phone.NUMBER, "1-800-GOOG-411") .withValue(Phone.TYPE, Phone.TYPE_CUSTOM) .withValue(Phone.LABEL, "free directory assistance")
.build()); try { getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); toast = Toast.makeText(ctx,"Deleted", duration); toast.show(); populateContactList();
} catch (Exception e) {
Log.e(TAG, "Exceptoin encoutered while deleting contact: " + e); }
to delete i used this coding
Code:
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); ops.add(ContentProviderOperation.newDelete(Data.CONTENT_URI) .withSelection(Data._ID + "=?", new String[]{String.valueOf(name)}) .build()); try { getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); toast = Toast.makeText(ctx,"Deleted", duration); toast.show(); populateContactList();
} catch (Exception e) {
Log.e(TAG, "Exceptoin encoutered while deleting contact: " + e); }
i both add and delete i am not getting any error, but it is not reflected nither in the contact nor in the textView.
please help me , i am a newbie.

adhavan is offline  
Reply With Quote
sponsored links
Old December 31st, 2011, 11:35 AM   #2 (permalink)
New Member
 
Join Date: Dec 2011
Posts: 3
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi All,
I know the code below opens the native Edit/Add contact screen

Intent newIntent = new Intent(Intent.ACTION_INSERT,
ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(newIntent, 1);

now i want this screen to be populated with some data in fields like
name, phone number, address etc. I found that if i do something like
newIntent.putExtra(ContactsContract.Intents.Insert .NAME, "Some
Name");
will show this screen with name "Some Name" being shown in the name
field this is fine for me now i dont understand how will i fill the
first name, last name , city, state and zip fields similarly.
I found the ContactsContract.Intents.Insert has a
POSTAL attribute for address but there are no specific attributes for
first name, last name, city, state and zip in ContactsContract.Intents.Insert.
Also i found that
ContactsContract.CommonDataKinds.StructuredPostal has the first name, last name, city, state
and zip attributes but still i dont know how can i use this to
prepopulate the Edit/Add contact screen with values of first name, last name, city, state
and zip.

Please Help me with this,
star
star007 is offline  
Reply With Quote
Reply
Tags
add contact, contact application, delete contact


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 06:32 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.