Q:

Retrieving Phone Numbers that are not deleted from the Android Contact List

I am trying to retrieve phone numbers from the ContactsContract that are not marked to be deleted.
@Override
public Loader onCreateLoader(int id, Bundle args) {
    return new CursorLoader(
            this,
            ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
            new String[]{
                    ContactsContract.CommonDataKinds.Phone.NUMBER
            },
            ContactsContract.CommonDataKinds.Phone.DELETED + "==0",
            null,
            null);
}

However, I am getting below error: 
java.lang.RuntimeException: An error occured while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:304)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
        at java.util.concurrent.FutureTask.run(FutureTask.java:242)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:818)
 Caused by: android.database.sqlite.SQLiteException: no such column: deleted (code 1): , while compiling: SELECT DISTINCT data1 FROM view_data data LEFT OUTER JOIN (SELECT data_usage_stat.data_id as STAT_DATA_ID, SUM(data_usage_stat.times_used) as times_used, MAX(data_usage_stat.last_time_used) as last_time_used FROM data_usage_stat GROUP BY data_usage_stat.data_id) as data_usage_stat ON (STAT_DATA_ID=data._id) WHERE (1 AND mimetype_id=5) AND ((deleted==0))
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:181)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
        at android.content.ContentProviderProxy.query(ContentProviderNative.java:421)
        at android.content.ContentResolver.query(ContentResolver.java:478)
        at android.content.CursorLoader.loadInBackground(CursorLoader.java:64)
        at android.content.CursorLoader.loadInBackground(CursorLoader.java:42)
        at android.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:312)
        at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:69)
        at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:57)
        at android.os.AsyncTask$2.call(AsyncTask.java:292)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)

The documentation for ContactsContract.CommonDataKinds.Phone.CONTENT_URI states that the data records will be combined with the associated raw contact and aggregate contact data. But "deleted" is not there. Why and how can I get only the phone numbers that are not deleted?

A:

The Data URI projection does not have the DELETED column, in any case your query should only retrieve the phone numbers of the contacts which are not deleted. Are you able to get phone numbers of deleted raw contacts? 

