I've looked at the other code fragments in this forum, and at the
sample code in the "Accessing Content Providers" document, but I'm
still having problems.  The following code fragment dies with an
IOException at
     uri = getContentResolver().insert(Contacts.People.CONTENT_URI,
contact);

Can someone please point out where I am going astray?

Thanks, Robert O'Hara

----------------------

import android.app.Activity;
import android.content.ContentValues;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts;
import android.provider.Contacts.Phones;
import android.view.KeyEvent;

public class Testbed extends Activity {
//
*************************************************************************************************
// Testbed is used to try out new program fragments.
//
*************************************************************************************************

public void onCreate(Bundle savedInstanceState) {
//
-------------------------------------------------------------------------------------------------
// Create our activity.
//
-------------------------------------------------------------------------------------------------
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

InsertContact("Harry Ijen", "+18142386651", 1);
}

public void InsertContact(String name, String phoneNumber, int
favorite) {
//
-------------------------------------------------------------------------------------------------
// Insert a new contact into the contacts application.
//
-------------------------------------------------------------------------------------------------
Uri phoneUri = null;
Uri uri = null;

ContentValues contact = new ContentValues();
contact.put(Contacts.People.NAME, name);
contact.put(Contacts.People.STARRED, favorite);
uri = getContentResolver().insert(Contacts.People.CONTENT_URI,
contact);

// Now get the CONTENT_URI of the contact we just inserted & build the
URI for the phone num.
phoneUri = Uri.withAppendedPath(uri,
Contacts.People.Phones.CONTENT_DIRECTORY);
contact.clear();
contact.put(Contacts.Phones.TYPE, Phones.TYPE_MOBILE);
contact.put(Contacts.Phones.NUMBER, phoneNumber);
getContentResolver().insert(phoneUri, contact);
}

public boolean onKeyUp(int keyCode, KeyEvent keyMsg) {
//
-------------------------------------------------------------------------------------------------
// Terminate the application if the user presses the Q key.
//
-------------------------------------------------------------------------------------------------
if (keyCode == KeyEvent.KEYCODE_Q) finish();
return true;
}

}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to