3

Ultimately I'm trying to see the icons of other apps installed on the device. The app icons can be gathered with PackageManager.getApplicationIcon(packageName) on the Android native side, but this returns a Drawable. https://developer.android.com/reference/android/content/pm/PackageManager.html#getApplicationIcon%28java.lang.String%29

How can I display that Drawable in my React Native app? Not worried about iOS cross-compatibility.

1 Answers1

4

From what I can understand, you simply want to show the app icon images in your react native view. If so, then you should follow these steps:

  1. Convert your Drawable to Bitmap. This does involves some native code which you can find in this answer - https://stackoverflow.com/a/3035869/5597641
  2. Convert the Bitmap to Base64 string. This can be found in https://stackoverflow.com/a/9224180/5597641
  3. Send the string to the react native side. Say, you have the base64 string in appIcon variable.

You can display it using the <Image/> component in react native as:

<Image style={{height: 50, width: 50}} resizeMode={'contain'} source={{uri: appIcon}} />
Dani Akash
  • 6,828
  • 3
  • 35
  • 47