Question

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");
            }
        }
    }
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top