0

I have this contact information from Whatsapp: 491766465xxxx@s.whatsapp.net

Obtained from this code

void startWhatsAppContactPicker() {
        Intent intent = new Intent(Intent.ACTION_PICK);
        intent.setPackage("com.whatsapp");
        try {
            startActivityForResult(intent, REQUEST_CODE_PICK_WHATSAPP);
        } catch (Exception e) {
            Toast.makeText(this, "Kein Whatsapp installiert", Toast.LENGTH_SHORT).show();
        }
    }


  @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case REQUEST_CODE_PICK_WHATSAPP:
                if (resultCode == RESULT_OK) {
                    if (data.hasExtra("contact")) {
                        String address = data.getStringExtra("contact");
                        Log.d(TAG, "The selected Whatsapp address is: " + address);
                  }
                }
                break;
            default:
                break;
        }
    }

Outputt: 49176646xxxx@s.whatsapp.net

Is this information stored in the Android contacts?

I need the contact to get the the name of the owner.

I have tryied this but without success:

How to get whatsapp Contacts from Android?

Cheers

Community
  • 1
  • 1

1 Answers1

0

Assuming the 49176646xxxx segment is a phone number, you can search the phone contacts for that phone number:

String address = data.getStringExtra("contact");
String phone = address.split("@")[0];
String[] projection = new String[] {Phone.DISPLAY_NAME, Phone.NUMBER, Phone.NORMALIZED_NUMBER };
String selection = Phone.NORMALIZED_NUMBER + " = " + phone;
Cursor c = cr.query(Phone.CONTENT_URI, projection, selection, null, null);
if (c != null && c.moveToFirst()) {
   Log.d(TAG, "name is: " + c.getString(0));
}

(note: Phone.NORMALIZED_NUMBER was added in API 16)

marmor
  • 27,641
  • 11
  • 107
  • 150