質問

i am starting contact app using intent and selecting the contact from the list each time i choose different contact but i am getting the same contact again and again and i also don't know which contact it is? I have no idea what is going on?

Here is my code

 Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
                      startActivityForResult(intent, PICK_CONTACT);

and in activity result

 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) 
     {
        super.onActivityResult(requestCode, resultCode, data);

        Cursor c = null;
        try
        {
            if(requestCode == PICK_CONTACT)
            {
                 Uri contactData = data.getData();
                 c =  getContentResolver().query(Phone.CONTENT_URI, null, null, null, null);
                    if (c.moveToFirst()) 
                    {
                      reciever = c.getString(c.getColumnIndex(Phone.NUMBER));
                      reciever = Main.removeCharacters(reciever);
                      int size = reciever.length();
                      Log.v(TAG, "To send "+reciever);
                      reciever = reciever.substring(size - 6, size);
                    }
              new UploadPic().execute("");
            }
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        finally
        {
            if(c != null)
            {
                c.close();
                Log.v(TAG, "Cursor Closed");
            }
        }
    }
役に立ちましたか?

解決

You are assigning the contact URI to contactData yet you do not use it. When you call query() pass in contactData for the first argument rather than Phone.CONTENT_URI.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top