How to open WhatsApp using an Intent in your Android App

Solution 1:

Using the 2018 api:

String url = "https://api.whatsapp.com/send?phone="+number;
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);

Solution 2:

This code working for me

String contact = "+00 9876543210"; // use country code with your phone number
    String url = "https://api.whatsapp.com/send?phone=" + contact;
    try {
         PackageManager pm = context.getPackageManager();
         pm.getPackageInfo("com.whatsapp", PackageManager.GET_ACTIVITIES);
         Intent i = new Intent(Intent.ACTION_VIEW);
         i.setData(Uri.parse(url));
         startActivity(i);                            
    } catch (PackageManager.NameNotFoundException e) {
    Toast.makeText(MainActivity.activity, "Whatsapp app not installed in your phone", Toast.LENGTH_SHORT).show();
    e.printStackTrace();
    }