2012-05-13 14 views
0

着信と発信のログを記録するアプリケーションを作成しようとしていますが、このコードを呼び出して発信者ID(氏名など)を返すようにはできないようですが、 "不明"発信者IDを取得する

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() > 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))) > 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; 

}

それはこの(if(phone==nbc||phone==num))部分を実行しません。

あなたは何が間違っているのか、これを行うための方法を教えてもらえますか、少なくとも正しい方向に向かうことができますか?

答えて

0

使用equalsStrings

if(phone.equals(nbc)||phone.equals(num)) 
を比較します
関連する問題