0

i want to launch Facebook app or Facebook Lite app on button click if installed otherwise open https://www.facebook.com/ url in browser. i have a code to know apps installed or not in device but i am facing a problem to launch any app if available on button click. Please provide me any best solution without Facebook SDK integration.

private fun isFbAppInstalled():Boolean{
    try {
        val info = activity!!.getPackageManager().getApplicationInfo("com.facebook.katana", 0)
        return true
    } catch (e: PackageManager.NameNotFoundException) {
        return false
    }

}
Davinder Goel
  • 763
  • 2
  • 8
  • 22
  • show us your code, let us see what you have tried – Akshay Katariya Feb 06 '18 at 05:35
  • It's simple then, inside your `Buttons` click listener call this `isFbAppInstalled()` if it returns true open facebook via intent – Akshay Katariya Feb 06 '18 at 05:41
  • that's the problem whose am facing am not able to launch fb app on click. it's show white screen only. if (isFbAppInstalled()){ val intent = Intent("android.intent.category.LAUNCHER") intent.setClassName("com.facebook.katana", "com.facebook.katana.LoginActivity") startActivity(intent) } – Davinder Goel Feb 06 '18 at 05:43

1 Answers1

1

This works for me, tested now.

if (isFbAppInstalled()) {

    String uri = "facebook:/newsfeed";
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
    startActivity(intent);
}
rupinderjeet
  • 2,984
  • 30
  • 54