I am writing a test case to for reading phone contact list

public class ContactTest extends AndroidTestCase {

        static final String LOG_TAG = "ContactTest";
    static final String TESTUSER_NAME = "Test User";
    static final String TESTUSER_NUMBER = "1234568909";
    ContentResolver contentResolver;
    Uri newPerson;



    public void setUp() {
        contentResolver = getContext().getContentResolver();

        ContentValues person = new ContentValues();
        person.put(ContactsContract.Contacts.DISPLAY_NAME,
TESTUSER_NAME );
        person.put(ContactsContract.CommonDataKinds.Phone.NUMBER,
TESTUSER_NUMBER );

        newPerson =
contentResolver.insert(ContactsContract.Contacts.CONTENT_URI,person);
    }

In Manifest file I have following permissions defined
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
    <uses-permission android:name="android.permission.READ_CONTACTS"/>

But while running the test it keeps throwing following permission
exception
java.lang.SecurityException: Permission Denial: writing
com.android.providers.contacts.ContactsProvider2 uri
content://com.android.contacts/contacts from pid=343, uid=10036
requires android.permission.WRITE_CONTACTS
at android.os.Parcel.readException(Parcel.java:1247)
at
android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:
160)
at
android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:
114)
at
android.content.ContentProviderProxy.insert(ContentProviderNative.java:
408)
at android.content.ContentResolver.insert(ContentResolver.java:587)
at com.aes.mobile.android.test.ContactTest.setUp(ContactTest.java:32)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:
520)
at android.app.Instrumentation
$InstrumentationThread.run(Instrumentation.java:1447)

Any idea?

Thanks,

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

Reply via email to