How do you display Drawables from Android in a React Native app?
I end up trying to see the icons of other apps installed on the device. App icons can be collected using PackageManager.getApplicationIcon(packageName)
the Android side, but this returns Drawable. https://developer.android.com/reference/android/content/pm/PackageManager.html#getApplicationIcon%28java.lang.String%29
How can I render this Drawable in a React Native app? Doesn't worry about iOS cross-compatibility.
+3
source to share
1 answer
From what I can understand, you just want to show the app icon images in your own react image. If yes, then you should follow these steps:
- Convert your Drawable to Bitmap . This includes some native code which you can find in this answer - fooobar.com/questions/12096 / ...
- Convert bitmap to Base64 string . This can be found at fooobar.com/questions/78352 / ...
- Send the string back to the native side . Let's say you have a base64 string in a variable
appIcon
.
You can render it using a component <Image/>
in the responsive native language as:
<Image style={{height: 50, width: 50}} resizeMode={'contain'} source={{uri: appIcon}} />
+4
source to share