Method to check if instagram is installed in android device

399 Views Asked by At

I am working on an expo app and trying to check if instagram if installed in my device or not so I can share content on it. I am using react-native-share and testing the code on dev build but all methods returns false even though instagram app is installed. The code snippet is attached

const isInstagramInstalled =
      Platform.OS === "ios"
        ? await Linking.canOpenURL("instagram://app")
        : (await Share.isPackageInstalled("com.instagram.android"))
            ?.isInstalled;

I've tried using Linking module but that doesn't work and returns wrong result, intent launcher but that opens instagram instead of giving a result. I have read about QUERY_ALL_PACKAGES but not sure either to use it or not as it makes issues while submitting the app on play store. I want a function that checks if instagram is installed or not and returns the correct answer, in case if instagram is not installed it opens website for it. The above snippet works fine for IOS but returns false on android

1

There are 1 best solutions below

0
On

I would suggest using shared-group-preferences library https://github.com/KjellConnelly/react-native-shared-group-preferences#extras-because-im-lazy

From its example, you may apply it for Instagram:

  import SharedGroupPreferences from 'react-native-shared-group-preferences'
   
   ...

  // Android only example from the library:
  const instagramPackageName = "com.instagram.android"
  try {
    const installed = await SharedGroupPreferences.isAppInstalledAndroid(instagramPackageName)
    console.log("instagram is installed on this device")
  } catch (err) {
    console.log("instagram is NOT installed")
  }
  import SharedGroupPreferences from 'react-native-shared-group-preferences'

  // for your example:
  const isInstagramInstalled =
      Platform.OS === "ios"
        ? await Linking.canOpenURL("instagram://app")
        : (await SharedGroupPreferences.isAppInstalledAndroid("com.instagram.android"))

Hope you find it helpful!