public boolean isAppAvailable(Context context, String appName) {
PackageManager pm = context.getPackageManager();
try {
pm.getPackageInfo(appName, PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
final String appName = "org.telegram.messenger";
final boolean isAppInstalled = isAppAvailable(getApplicationContext(), appName);
if (isAppInstalled) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://t.me/joinchat/BSLSdUJkvhEVnDI4lbNw3g"));
startActivity(intent);
} else {
String msg = getResources().getString(R.string.telegram_not_installed);
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
}
References
https://stackoverflow.com/questions/35721942/how-to-launch-telegram-app-from-my-own-android-application
Related