After playing around for a long while I realized that we can launch the Whatsapp's contact picker activity and receive the results back, but not in the returned uri (the way Android contact picker does) but as an extra.
I've come up with the following solution.
To start the Whatsapp's native contact picker we call the following code from our activity:
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setPackage("com.whatsapp");
try{
startActivityForResult(intent, REQUEST_CODE_PICK_WHATSAPP);
} catch (Exception e) {
Toast.makeText(MainActivity.this, R.string.notif_no_whatsapp, Toast.LENGTH_SHORT).show(); //no activity found to handle this intent means whatsapp is not installed
}
Then, inside activity's onActivityResult(...) method:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
switch (requestCode) {
case REQUEST_CODE_PICK_WHATSAPP:
if(resultCode == RESULT_OK){
if(intent.hasExtra("contact")){
String address = intent.getStringExtra("contact");
Log.d(TAG, "The selected Whatsapp address is: "+address);
}
}
break;
default:
break;
}
}
Hope it contributes to make more apps that integrate with Whatsapp seamlessly.