Getting contact name from number in Android 2.3.4
<p>i try to get the name of contact using number in 2.3.4 android, but it was not working.. here i have attached my code. Kindly assist.. i have tried so many ways as posted in Stack over flow, in emulator its working but fails while runs in phone..</p>

<pre><code>String[] projection = new String[] { Contacts.Phones.DISPLAY_NAME, 
                                     Contacts.Phones.NUMBER };

// encode the phone number and build the filter URI
Toast.makeText(context, "sender: "+sender, Toast.LENGTH_LONG).show();

Uri contactUri = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL,
                                      Uri.encode(sender));

// query time
Cursor c = context.getContentResolver().query(contactUri, projection, null,
                                              null, null);

// if the query returns 1 or more results
// return the first result
if(c.getCount()&gt;0){
    if (c.moveToFirst()) {
        name = c.getString(c.getColumnIndex(Contacts.Phones.DISPLAY_NAME));
    }                
}else{
    name="UnKnown";
}
</code></pre>
