I've been searching the internet for quite a while now and still couldn't find a way to send a message automatically. So far what my app can does is open up the Whatsapp to a certain contact and write down the message I want to send. Here is my code :
This code is to check if Whatsapp is installed on the device
private boolean checkWA(String uri) {
PackageManager packageManager = getPackageManager();
boolean appInstalled;
try {
packageManager.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
appInstalled = true;
}
catch (PackageManager.NameNotFoundException e) {
appInstalled = false;
}
return appInstalled;
}
This code is to intent to Whatsapp (couldn't auto send message)
public void onClickWhatsApp() {
boolean installed = checkWA("com.whatsapp");
if (installed){
String url = "https://api.whatsapp.com/send/?phone=6282167975500&text=" + "ADDON ERROR";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setPackage("com.whatsapp");
i.setData(Uri.parse(url));
startActivity(i);
}
else {
String url = "https://api.whatsapp.com/send/?phone=6282167975500&text=" + "ADDON ERROR";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
}
Does anyone know how to do the auto send part? Thanks.