Get the caller id
<p>I'm trying to make app which will log my incoming and outgoing calls and the problem is i can't seem to get working this code to return caller id(Like name and surname) but it allways returns "Unknown"</p>

<pre><code>public String getname(String num,String nbc ){
String namer="";
 ContentResolver cr = getContentResolver();
 Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
        null, null, null, null);



 try {
  if (cur.getCount() &gt; 0) {
     while (cur.moveToNext()) {
           String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
           String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
            Log.i("",name);

           if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) &gt; 0) {
                System.out.println("name : " + name + ", ID : " + id);

               // get the phone number

               Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,
                                      ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
                                      new String[]{id}, null);
               while (pCur.moveToNext()) {

                     String phone = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

                     System.out.println("phone" + phone);
                     if(phone==nbc||phone==num)
                    {
                         namer = name;
                         return namer;
                    }                        

               }
               pCur.close();
           }

     }       
 }
 }
 catch (Exception e) {
    // TODO: handle exception
}

     return namer;
</code></pre>

<p>}</p>

<p>It doesn't execute this(<code>if(phone==nbc||phone==num)</code>) part. </p>

<p>Can you please tell me what's wrong or another way to do this or at least point me in the right direction.</p>
