All android apps have unique id, so first we have to check if these apps are installed in user's device and then we can pass the unique id via intent for sharing. Do according below:
Unique ids for different apps :
Viber : com.viber.voip
Telegram : org.telegram.messenger
Whatsapp : com.whatsapp
Check if these apps are installed and if installed then send messages through intent.
private void sendMessage(Context context,String message, String appIds)
{
final boolean isAppInstalled =isAppAvailable(context, appIds);
if (isAppInstalled)
{
Intent myIntent = new Intent(Intent.ACTION_SEND);
myIntent.setType("text/plain");
myIntent.setPackage(appIds);
myIntent.putExtra(Intent.EXTRA_TEXT, message);
mUIActivity.startActivity(Intent.createChooser(myIntent, "Share with"));
}
else
{
Toast.makeText(context, "App not Installed", Toast.LENGTH_SHORT).show();
}
}
Indicates whether the specified app installed and can used as an intent. This
method checks the package manager for installed packages that can respond to an intent with the specified app. If no suitable package is found, this method returns false.
private boolean isAppAvailable(Context context, String appName)
{
PackageManager pm = context.getPackageManager();
try
{
pm.getPackageInfo(appName, PackageManager.GET_ACTIVITIES);
return true;
}
catch (NameNotFoundException e)
{
return false;
}
}