Skip to content

Commit

Permalink
--update check of installed app
Browse files Browse the repository at this point in the history
  • Loading branch information
Anshul1507 committed Apr 15, 2020
1 parent 2f92d83 commit 6db2464
Showing 1 changed file with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
Expand All @@ -25,25 +28,68 @@ protected void onCreate(Bundle savedInstanceState) {
final CustomChromeTabView customChromeTabView = new CustomChromeTabView();
customChromeTabView.customTabLinking(fbURL, getApplicationContext());

PackageManager pm = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
pm = (getApplicationContext()).getPackageManager();
}
final PackageManager finalPm = pm;

fbBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
customChromeTabView.customTabLinking(fbURL,getApplicationContext());
String fbPN = "com.facebook.katana";
if(isPackageInstalled(fbPN, finalPm)) {
//if app is installed, open it in app
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(fbPN)));
}else{
// if not, open in chrome custom tabs
CustomChromeTabView customChromeTabView = new CustomChromeTabView();
customChromeTabView.customTabLinking(fbURL, getApplicationContext());
}
}
});


telegramBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
customChromeTabView.customTabLinking(telegramURL,getApplicationContext());
String telegramPN = "org.telegram.messenger"; //for telegram
String telegramXPN = "org.thunderdog.challegram"; //for telegram-X
if(isPackageInstalled(telegramPN, finalPm)) {
//if app is installed, open it in app
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(telegramURL)));
}else if(isPackageInstalled(telegramXPN,finalPm)){
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(telegramURL)));
}
else{
// if not, open in chrome custom tabs
CustomChromeTabView customChromeTabView = new CustomChromeTabView();
customChromeTabView.customTabLinking(telegramURL, getApplicationContext());
}
}
});

discordBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
customChromeTabView.customTabLinking(discordURL,getApplicationContext());
String discordPN = "com.discord";
if(isPackageInstalled(discordPN, finalPm)) {
//if app is installed, open it in app
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(discordURL)));
}else{
// if not, open in chrome custom tabs
CustomChromeTabView customChromeTabView = new CustomChromeTabView();
customChromeTabView.customTabLinking(discordURL, getApplicationContext());
}
}
});
}
private boolean isPackageInstalled(String packageName, PackageManager packageManager) {
try {
packageManager.getPackageInfo(packageName, 0);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
}

0 comments on commit 6db2464

Please sign in to comment.