Get the list of installed apps on Android

How can I get the list of installed apps on Android using expo. I tried to use this library (https://www.npmjs.com/package/react-native-android-installed-apps) but getting errors


TypeError: null is not an object (evaluating 'RNAndroidInstalledApps.getApps')
- node_modules/react-native-android-installed-apps/index.js:10:34 in getApps
* App.js:26:4 in componentDidMount
- node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js:15036:10 in commitLifeCycles
- node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js:16636:8 in commitAllLifeCycles
- ... 21 more stack frames from framework internals

Here is the relevent code related to the error:

componentDidMount() {
    RNAndroidInstalledApps.getApps()
      .then(apps => {
        console.log(apps);
      })
      .catch(error => {
        alert(error);
      });
  }

Hi. Did you eject?

The installation documentation says:

$ react-native link react-native-android-installed-apps

So (unless Expo already includes this library) this means you have to eject in order to use it.

It says react native command not found. Doesn’t expo install the react-native?

(base) arun@arun-HP-Pavilion-g6-Notebook-PC:~/Videos/mytestreactnative$ react-native link react-native-android-installed-apps
react-native: command not found
(base) arun@arun-HP-Pavilion-g6-Notebook-PC:~/Videos/mytestreactnative$

Please answer the questions I ask.

I see the android and ios directories already in the project folder. Also I ran the command expo eject and I got an error.

Warning! Your git working tree is dirty.
It's recommended to commit all your changes before proceeding,
so you can revert the changes made by this command if necessary.

? How would you like to eject your app?
  Read more: https://docs.expo.io/versions/latest/expokit/eject/ ExpoKit
Error detaching. `ios` and `android` directories already exist.
(base) arun@arun-HP-Pavilion-g6-Notebook-PC:~/Videos/mytestreactnative$ 

Should I remove the android and ios folders and eject the app?

Let’s start at the beginning. How did you create the app in the first place? Is this the same app from your other question that seems to be using something other than an Expo SDK for the ‘react-native’ dependency in package.json?

@wodin Yes. I had created the project using the expo. and it’s the same app that I’m trying to use. I had made some changes to the package.json file:

{
  "scripts": {
    "postinstall": "jetify",
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "web": "expo start --web",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "expo-constants": "6.0.0",
    "react": "16.8.3",
    "react-native": "https://github.com/expo/react-native/archive/sdk-34.0.1.tar.gz",
    "react-native-easy-grid": "^0.2.2",
    "react-native-paper": "^2.16.0",
    "react-test-renderer": "16.9.0"
  },
  "devDependencies": {
    "@babel/core": "^7.6.0",
    "babel-jest": "24.9.0",
    "expo": "^34.0.3",
    "jest": "24.9.0",
    "jetifier": "^1.6.4",
    "metro-react-native-babel-preset": "0.56.0",
    "react": "16.8.3",
    "react-native": "https://github.com/expo/react-native/archive/sdk-34.0.1.tar.gz",
    "react-native-android-installed-apps": "^1.0.1",
    "react-test-renderer": "16.9.0"
  },
  "jest": {
    "preset": "react-native"
  },
  "private": true
}

I’m trying to understand the discrepancies between the versions mentioned here and what you pasted above. Also the “scripts” section of your package.json is not what you would get by default when running expo init. Could you please let me know more about the history of your app?

Did you, for example, do something like this?

  1. expo init mytestreactnative
  2. <edit JS and maybe run expo install or npm install>
  3. <change package.json to use "react-native": "^0.60.5" instead of the Expo SDK>
  4. expo eject
  5. npm install react-native-android-installed-apps --save? (You don’t have it listed as a dependency.)
  6. ???
  7. <change package.json to use "react-native": "https://github.com/expo/react-native/archive/sdk-34.0.1.tar.gz">

If so, why did you change the react-native dependency in package.json to “^0.60.5” before?

You can try running npx react-native link ... instead of react-native link ..., but if it still doesn’t work you are going to have to provide some more history. Another option would be to create a new app from scratch like this:

  1. expo init newapp
  2. expo eject
  3. npm install react-native-android-installed-apps
  4. npx react-native link react-native-android-installed-apps

@wodin I tried to create new app but still got the same error. I had choosen the bare minimum template for app and expokit for ejecting.

base) arun@arun-HP-Pavilion-g6-Notebook-PC:~/Videos$ expo init simple-launcher
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                                                                                                          │
│   There is a new version of expo-cli available (3.1.2).                                                                                  │
│   You are currently using expo-cli 3.1.0                                                                                                 │
│   Install expo-cli globally using the package manager of your choice; for example: `npm install -g expo-cli` to get the latest version   │
│                                                                                                                                          │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
? Choose a template: expo-template-bare-minimum
Project name can only include ASCII characters A-Z, a-z and 0-9
(base) arun@arun-HP-Pavilion-g6-Notebook-PC:~/Videos$ expo init simplelauncher
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                                                                                                          │
│   There is a new version of expo-cli available (3.1.2).                                                                                  │
│   You are currently using expo-cli 3.1.0                                                                                                 │
│   Install expo-cli globally using the package manager of your choice; for example: `npm install -g expo-cli` to get the latest version   │
│                                                                                                                                          │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
? Choose a template: expo-template-bare-minimum
✔ Please enter names for your project. · 100% completed
Extracting project files...
Customizing project...
Initialized a git repository.
Installing dependencies...
npm WARN deprecated deep-assign@3.0.0: Check out `lodash.merge` or `merge-options` instead.
npm WARN deprecated core-js@1.2.7: core-js@<2.6.8 is no longer maintained. Please, upgrade to core-js@3 or at least to actual version of core-js@2.
npm WARN deprecated left-pad@1.3.0: use String.prototype.padStart()

> core-js@2.6.9 postinstall /home/arun/Videos/simplelauncher/node_modules/fbjs-scripts/node_modules/core-js
> node scripts/postinstall || echo "ignore"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
> https://opencollective.com/core-js 
> https://www.patreon.com/zloirock 

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> core-js@2.6.9 postinstall /home/arun/Videos/simplelauncher/node_modules/metro-babel-register/node_modules/core-js
> node scripts/postinstall || echo "ignore"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
> https://opencollective.com/core-js 
> https://www.patreon.com/zloirock 

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> core-js@2.6.9 postinstall /home/arun/Videos/simplelauncher/node_modules/metro/node_modules/core-js
> node scripts/postinstall || echo "ignore"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
> https://opencollective.com/core-js 
> https://www.patreon.com/zloirock 

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> core-js@2.6.9 postinstall /home/arun/Videos/simplelauncher/node_modules/react-native-web/node_modules/core-js
> node scripts/postinstall || echo "ignore"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
> https://opencollective.com/core-js 
> https://www.patreon.com/zloirock 

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> core-js@2.6.9 postinstall /home/arun/Videos/simplelauncher/node_modules/react-native/node_modules/core-js
> node scripts/postinstall || echo "ignore"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
> https://opencollective.com/core-js 
> https://www.patreon.com/zloirock 

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> react-native-unimodules@0.5.4 postinstall /home/arun/Videos/simplelauncher/node_modules/react-native-unimodules
> node ./scripts/postinstall.js


Successfully installed react-native-unimodules. This package contains core unimodules that are commonly depended on by other unimodules. You will need to configure your project before using other unimodules like expo-camera, expo-media-library and others.
See configuration guide:
  https://www.npmjs.com/package/react-native-unimodules/v/0.5.4


> undefined postinstall /home/arun/Videos/simplelauncher
> jetify

Jetifier found 1294 file(s) to forward-jetify. Using 4 workers...
npm notice created a lockfile as package-lock.json. You should commit this file.
added 1347 packages from 600 contributors and audited 920000 packages in 194.071s
found 11 low severity vulnerabilities
  run `npm audit fix` to fix them, or `npm audit` for details

Your project is ready at /home/arun/Videos/simplelauncher

Before running your app on iOS, make sure you have CocoaPods installed and initialize the project:

  cd simplelauncher/ios
  pod install

Then you can run the project:

  cd simplelauncher
  npm run android
  npm run ios

(base) arun@arun-HP-Pavilion-g6-Notebook-PC:~/Videos$ cd simplelauncher/
(base) arun@arun-HP-Pavilion-g6-Notebook-PC:~/Videos/simplelauncher$ expo eject
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                                                                                                          │
│   There is a new version of expo-cli available (3.1.2).                                                                                  │
│   You are currently using expo-cli 3.1.0                                                                                                 │
│   Install expo-cli globally using the package manager of your choice; for example: `npm install -g expo-cli` to get the latest version   │
│                                                                                                                                          │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Warning! Your git working tree is dirty.
It's recommended to commit all your changes before proceeding,
so you can revert the changes made by this command if necessary.

? How would you like to eject your app?
  Read more: https://docs.expo.io/versions/latest/expokit/eject/ ExpoKit
Error detaching. `ios` and `android` directories already exist.
(base) arun@arun-HP-Pavilion-g6-Notebook-PC:~/Videos/simplelauncher$ 

Ah, sorry, I forgot you could use expo init to immediately create an ejected app, in which case you would not have to eject afterwards.

OK, now if you run the following you should be all set (I hope):

npm install react-native-android-installed-apps
npx react-native link react-native-android-installed-apps