Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open Social media links in related apps from Android studio?

Tags:

java

android

uri

I am creating an app where user clicks on different social media links. The links are from different media including Facebook, Youtube and WhatsApp etc.

What I want is:

When user clicks on a Facebook link, the program checks if there is Facebook app installed in the user's phone and open the link in it. Similarly for other media.

I have tried a little with this code:

Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        context.startActivity(intent);

But it opens all the link in browser. I am new to android, kindly help! Thanks in advance...

like image 729
Muzzammil Hussain Avatar asked Nov 12 '19 08:11

Muzzammil Hussain


Video Answer


1 Answers

The package name can be used to launch the application.

Intent intent = getPackageManager().getLaunchIntentForPackage("com.package.name");
if (intent != null) {
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
} else {
    // Open GooglePlay link to install the app
}
like image 63
Aspicas Avatar answered Oct 19 '22 19:10

Aspicas