I want to send a text message via whatsapp from my app.
I do not know who the recepient is when i send the request to share via whatsapp i am directed to the contacts page.
How do I know which contact was chosen ?
This is the code I am using to share :
public void clickHandler(View view) {
PackageManager pm=getPackageManager();
try {
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
String text = "YOUR TEXT HERE";
PackageInfo info=pm.getPackageInfo("com.whatsapp",PackageManager.GET_META_DATA);
//Check if package exists or not. If not then code
//in catch block will be called
waIntent.setPackage("com.whatsapp");
waIntent.putExtra(Intent.EXTRA_TEXT, text);
startActivityForResult(Intent.createChooser(waIntent, "Share with"),1);
} catch (NameNotFoundException e) {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("whatsapp","requestCode:"+requestCode + " resultCode:"+resultCode+ " intent:"+data);
}
10-01 16:57:46.910: D/whatsapp(13522): requestCode:1 resultCode:0 intent:null